Upload from upload_mods.ps1
This commit is contained in:
321
Scripts/Entities/EntityAnimalChickenRebirth.cs
Normal file
321
Scripts/Entities/EntityAnimalChickenRebirth.cs
Normal file
@@ -0,0 +1,321 @@
|
||||
using Audio;
|
||||
using System.Globalization;
|
||||
|
||||
public class EntityAnimalChickenRebirth : EntityAnimalRabbit
|
||||
{
|
||||
public float flCaptureDistance = 2;
|
||||
public int numFeedInterval = 20;
|
||||
public ulong FeedIntervalTicks = 0UL;
|
||||
|
||||
public string[] entityNames;
|
||||
public string strName = "NotSet";
|
||||
|
||||
public string feedType = "";
|
||||
public int feedAmount = 0;
|
||||
public int numUpdateInterval = 1;
|
||||
public ulong UpdateIntervalTicks = 0UL;
|
||||
|
||||
public int numHealthLossPerFeedInterval = 1;
|
||||
public TileEntityAnimalChickenRebirth tileEntityAnimalChickenRebirth;
|
||||
public Vector3i homePos = Vector3i.zero;
|
||||
public bool homeSet = false;
|
||||
|
||||
public override void Write(BinaryWriter _bw, bool _bNetworkWrite)
|
||||
{
|
||||
base.Write(_bw, _bNetworkWrite);
|
||||
_bw.Write(strName);
|
||||
StreamUtils.Write(_bw, homePos);
|
||||
}
|
||||
|
||||
public override void Read(byte _version, BinaryReader _br)
|
||||
{
|
||||
base.Read(_version, _br);
|
||||
strName = _br.ReadString();
|
||||
|
||||
try
|
||||
{
|
||||
homePos = StreamUtils.ReadVector3i(_br);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3i HomePosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return homePos;
|
||||
}
|
||||
set
|
||||
{
|
||||
homePos = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return EntityName;
|
||||
}
|
||||
|
||||
public override string EntityName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!EntityClass.entityClassName.Contains("PickedUp"))
|
||||
{
|
||||
return Localization.Get("animalChicken");
|
||||
}
|
||||
|
||||
return strName;
|
||||
}
|
||||
}
|
||||
|
||||
public override void SetEntityName(string _name)
|
||||
{
|
||||
if (strName == "NotSet")
|
||||
{
|
||||
string randomName = RebirthUtilities.GetRandomName(this);
|
||||
|
||||
if (!string.IsNullOrEmpty(randomName))
|
||||
{
|
||||
_name = randomName;
|
||||
}
|
||||
}
|
||||
|
||||
if (_name.Equals(entityName)) return;
|
||||
|
||||
entityName = _name;
|
||||
HandleSetNavName();
|
||||
}
|
||||
|
||||
public override void CopyPropertiesFromEntityClass()
|
||||
{
|
||||
base.CopyPropertiesFromEntityClass();
|
||||
EntityClass entityClass = EntityClass.list[this.entityClass];
|
||||
|
||||
if (entityClass.Properties.Values.ContainsKey("CaptureDistance"))
|
||||
{
|
||||
flCaptureDistance = StringParsers.ParseFloat(entityClass.Properties.Values["CaptureDistance"], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
if (entityClass.Properties.Values.ContainsKey("FeedInterval"))
|
||||
{
|
||||
numFeedInterval = (int)StringParsers.ParseFloat(entityClass.Properties.Values["FeedInterval"], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
if (entityClass.Properties.Values.ContainsKey("FeedType"))
|
||||
{
|
||||
feedType = entityClass.Properties.Values["FeedType"];
|
||||
}
|
||||
if (entityClass.Properties.Values.ContainsKey("FeedAmount"))
|
||||
{
|
||||
feedAmount = (int)StringParsers.ParseFloat(entityClass.Properties.Values["FeedAmount"], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
if (entityClass.Properties.Values.ContainsKey("HealthLossPerFeedInterval"))
|
||||
{
|
||||
numHealthLossPerFeedInterval = (int)StringParsers.ParseFloat(entityClass.Properties.Values["HealthLossPerFeedInterval"], 0, -1, NumberStyles.Any);
|
||||
}
|
||||
|
||||
string randomName = RebirthUtilities.GetRandomName(this);
|
||||
|
||||
if (randomName != "")
|
||||
{
|
||||
strName = randomName;
|
||||
entityName = strName;
|
||||
HandleSetNavName();
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EntityAnimalChickenRebirth-CopyPropertiesFromEntityClass 2");
|
||||
string allNames = entityClass.Properties.Values["EntityNamesA"] + "," +
|
||||
entityClass.Properties.Values["EntityNamesB"] + "," +
|
||||
entityClass.Properties.Values["EntityNamesC"] + "," +
|
||||
entityClass.Properties.Values["EntityNamesD"] + "," +
|
||||
entityClass.Properties.Values["EntityNamesE"] + "," +
|
||||
entityClass.Properties.Values["EntityNamesF"] + "," +
|
||||
entityClass.Properties.Values["EntityNamesG"] + "," +
|
||||
entityClass.Properties.Values["EntityNamesH"] + "," +
|
||||
entityClass.Properties.Values["EntityNamesI"];
|
||||
|
||||
entityNames = allNames.Replace(" ", "").Split(new char[] { ',' });
|
||||
|
||||
System.Random r = new System.Random();
|
||||
int rInt = r.Next(0, entityNames.Length - 1);
|
||||
|
||||
strName = entityNames[rInt];
|
||||
//Log.Out("EntityAnimalChickenRebirth-CopyPropertiesFromEntityClass 2 strName: " + strName);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnUpdateLive()
|
||||
{
|
||||
try
|
||||
{
|
||||
base.OnUpdateLive();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Log.Out("EntityAnimalChickenRebirth-OnUpdateLive ERROR: " + ex.Message);
|
||||
|
||||
// why would the base method throw an exception here?
|
||||
}
|
||||
|
||||
if (!SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer) return;
|
||||
|
||||
if (EntityClass.entityClassName.Contains("PickedUp"))
|
||||
{
|
||||
//Log.Out("EntityAnimalChickenRebirth-OnUpdateLive IS PickedUp");
|
||||
/*Log.Out("EntityAnimalChickenRebirth-OnUpdateLive GameTimer.Instance.ticks - FeedIntervalTicks: " + (GameTimer.Instance.ticks - FeedIntervalTicks));
|
||||
Log.Out("EntityAnimalChickenRebirth-OnUpdateLive (ulong)(numFeedInterval * 20): " + ((ulong)(numFeedInterval * 20)));*/
|
||||
|
||||
if (GameTimer.Instance.ticks - FeedIntervalTicks > (ulong)(numFeedInterval * 20))
|
||||
{
|
||||
//Log.Out("EntityAnimalChickenRebirth-OnUpdateLive WITHIN INTERVAL");
|
||||
if (RebirthUtilities.GetFood(world, new Vector3i(position.x, position.y, position.z), 3, 30, feedType, feedAmount, "FuriousRamsayBucket001"))
|
||||
{
|
||||
//Log.Out("EntityAnimalChickenRebirth-OnUpdateLive BEEN FED");
|
||||
|
||||
// is this supposed to do something?
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("EntityAnimalChickenRebirth-OnUpdateLive HAS NOT BEEN FED");
|
||||
Health = Health - numHealthLossPerFeedInterval;
|
||||
if (Health > 0)
|
||||
{
|
||||
Buffs.AddBuff("FuriousRamsayChickenPain");
|
||||
}
|
||||
}
|
||||
|
||||
FeedIntervalTicks = GameTimer.Instance.ticks;
|
||||
}
|
||||
|
||||
if (GameTimer.Instance.ticks - UpdateIntervalTicks > (ulong)(numUpdateInterval * 20))
|
||||
{
|
||||
//Log.Out("EntityAnimalChickenRebirth-OnUpdateLive UpdateInterval TICK");
|
||||
//Log.Out("EntityAnimalChickenRebirth-OnUpdateLive GameTimer.Instance.ticks: " + GameTimer.Instance.ticks);
|
||||
if (HomePosition != Vector3i.zero)
|
||||
{
|
||||
//Log.Out("EntityAnimalChickenRebirth-OnUpdateLive Home Position exists!");
|
||||
|
||||
BlockValue block = world.GetBlock(HomePosition);
|
||||
|
||||
if (block.Block is BlockCoopRebirth)
|
||||
{
|
||||
//Log.Out("EntityAnimalChickenRebirth-OnUpdateLive Home Position IS COOP!");
|
||||
|
||||
// do we do something here?
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Out("======================================================================================");
|
||||
//Log.Out("homePos RESET");
|
||||
HomePosition = Vector3i.zero;
|
||||
UpdateIntervalTicks = GameTimer.Instance.ticks;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
UpdateIntervalTicks = GameTimer.Instance.ticks;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void PostInit()
|
||||
{
|
||||
//Log.Out("EntityAnimalChickenRebirth-GetActivationCommands START");
|
||||
base.PostInit();
|
||||
|
||||
if (tileEntityAnimalChickenRebirth == null)
|
||||
{
|
||||
//Log.Out("EntityAnimalChickenRebirth-GetActivationCommands 1");
|
||||
tileEntityAnimalChickenRebirth = new TileEntityAnimalChickenRebirth(null);
|
||||
tileEntityAnimalChickenRebirth.entityId = entityId;
|
||||
}
|
||||
|
||||
cmds = new EntityActivationCommand[] { new EntityActivationCommand("capture", "capture", true) };
|
||||
}
|
||||
|
||||
public override EntityActivationCommand[] GetActivationCommands(Vector3i _tePos, EntityAlive _entityFocusing)
|
||||
{
|
||||
//Log.Out("EntityAnimalChickenRebirth-GetActivationCommands START");
|
||||
if (IsDead())
|
||||
{
|
||||
//Log.Out("EntityAnimalChickenRebirth-GetActivationCommands 1");
|
||||
return new EntityActivationCommand[0];
|
||||
}
|
||||
|
||||
//Log.Out("EntityAnimalChickenRebirth-GetActivationCommands 2");
|
||||
cmds[0].enabled = true;
|
||||
return cmds;
|
||||
}
|
||||
|
||||
public override bool OnEntityActivated(int _indexInBlockActivationCommands, Vector3i _tePos, EntityAlive _entityFocusing)
|
||||
{
|
||||
//Log.Out("EntityAnimalChickenRebirth-OnEntityActivated START");
|
||||
LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(_entityFocusing as EntityPlayerLocal);
|
||||
|
||||
if (_indexInBlockActivationCommands == 0)
|
||||
{
|
||||
//Log.Out("EntityAnimalChickenRebirth-OnEntityActivated 1");
|
||||
string strItem = "FuriousRamsayAnimalChicken001Spawn";
|
||||
|
||||
if (HasAnyTags(FastTags<TagGroup.Global>.Parse("FuriousRamsayAnimalChicken002")))
|
||||
{
|
||||
//Log.Out("EntityAnimalChickenRebirth-OnEntityActivated 2");
|
||||
strItem = "FuriousRamsayAnimalChicken002Spawn";
|
||||
}
|
||||
else if (HasAnyTags(FastTags<TagGroup.Global>.Parse("FuriousRamsayAnimalChicken003")))
|
||||
{
|
||||
//Log.Out("EntityAnimalChickenRebirth-OnEntityActivated 3");
|
||||
strItem = "FuriousRamsayAnimalChicken003Spawn";
|
||||
}
|
||||
else if (HasAnyTags(FastTags<TagGroup.Global>.Parse("FuriousRamsayAnimalChicken004")))
|
||||
{
|
||||
//Log.Out("EntityAnimalChickenRebirth-OnEntityActivated 4");
|
||||
strItem = "FuriousRamsayAnimalChicken004Spawn";
|
||||
}
|
||||
|
||||
ItemValue itemQuickHeal = ItemClass.GetItem(strItem, false);
|
||||
ItemClass itemClass = itemQuickHeal.ItemClass;
|
||||
ItemStack @is = new ItemStack(new ItemValue(itemClass.Id, false), 1);
|
||||
_entityFocusing.inventory.AddItem(@is);
|
||||
|
||||
Vector3i coopPosition = homePos;
|
||||
|
||||
Manager.PlayInsidePlayerHead("chickenpain");
|
||||
|
||||
//Log.Out("EntityAnimalChickenRebirth-OnEntityActivated entityID: " + entityID);
|
||||
if (!SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer)
|
||||
{
|
||||
SingletonMonoBehaviour<ConnectionManager>.Instance.SendToServer(NetPackageManager.GetPackage<NetPackageDespawnEntityRebirth>().Setup(entityId), false);
|
||||
}
|
||||
else
|
||||
{
|
||||
bIsChunkObserver = false;
|
||||
bWillRespawn = false;
|
||||
int entityID = entityId;
|
||||
|
||||
DamageResponse damageResponse = new DamageResponse
|
||||
{
|
||||
Fatal = true,
|
||||
Source = new DamageSource(EnumDamageSource.External, EnumDamageTypes.Bashing),
|
||||
Strength = 999999,
|
||||
Critical = true,
|
||||
HitDirection = Utils.EnumHitDirection.None,
|
||||
MovementState = this.MovementState,
|
||||
Random = rand.RandomFloat,
|
||||
ImpulseScale = 1
|
||||
};
|
||||
|
||||
damageResponse.Fatal = true;
|
||||
damageResponse.Strength = 999999;
|
||||
timeStayAfterDeath = 0;
|
||||
Kill(damageResponse);
|
||||
bWillRespawn = false;
|
||||
GameManager.Instance.World.RemoveEntity(entityId, EnumRemoveEntityReason.Despawned);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user