Upload from upload_mods.ps1
This commit is contained in:
192
Scripts/Items/ItemClassTimeBombSDX.cs
Normal file
192
Scripts/Items/ItemClassTimeBombSDX.cs
Normal file
@@ -0,0 +1,192 @@
|
||||
public class ItemClassTimeBombSDX : ItemClass
|
||||
{
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
this.explosion = new ExplosionData(this.Properties);
|
||||
this.Properties.ParseBool("ExplodeOnHit", ref this.bExplodeOnHitGround);
|
||||
this.Properties.ParseBool("FuseStartOnDrop", ref this.dropStarts);
|
||||
this.Properties.ParseBool("FusePrimeOnActivate", ref this.mustPrime);
|
||||
string text = "";
|
||||
this.Properties.ParseString("ActivationTransformToHide", ref text);
|
||||
this.activationTransformToHide = text.Split(new char[]
|
||||
{
|
||||
';'
|
||||
});
|
||||
float num = 2f;
|
||||
this.Properties.ParseFloat("FuseTime", ref num);
|
||||
this.explodeAfterTicks = (int)(num * 20f);
|
||||
}
|
||||
|
||||
public override void StartHolding(ItemInventoryData _data, Transform _modelTransform)
|
||||
{
|
||||
base.StartHolding(_data, _modelTransform);
|
||||
this.OnHoldingReset(_data);
|
||||
this.activateHolding(_data.itemValue, 0, _modelTransform);
|
||||
_data.Changed();
|
||||
}
|
||||
|
||||
public override void OnHoldingItemActivated(ItemInventoryData _data)
|
||||
{
|
||||
ItemValue itemValue = _data.itemValue;
|
||||
if (itemValue.Meta != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.setActivationTransformsActive(_data.holdingEntity.inventory.models[_data.holdingEntity.inventory.holdingItemIdx], true);
|
||||
_data.holdingEntity.RightArmAnimationUse = true;
|
||||
int ticks = this.explodeAfterTicks;
|
||||
if (this.mustPrime)
|
||||
{
|
||||
ticks = -1;
|
||||
}
|
||||
this.activateHolding(itemValue, ticks, _data.model);
|
||||
_data.Changed();
|
||||
AudioSource audioSource = (_data.model != null) ? _data.model.GetComponentInChildren<AudioSource>() : null;
|
||||
if (audioSource)
|
||||
{
|
||||
audioSource.Play();
|
||||
}
|
||||
if (!_data.holdingEntity.isEntityRemote)
|
||||
{
|
||||
_data.gameManager.SimpleRPC(_data.holdingEntity.entityId, SimpleRPCType.OnActivateItem, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnHoldingUpdate(ItemInventoryData _data)
|
||||
{
|
||||
base.OnHoldingUpdate(_data);
|
||||
if (_data.holdingEntity.isEntityRemote)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ItemValue itemValue = _data.itemValue;
|
||||
if (itemValue.Meta > 0)
|
||||
{
|
||||
itemValue.Meta--;
|
||||
if (itemValue.Meta == 0)
|
||||
{
|
||||
Vector3 vector = (_data.model != null) ? (_data.model.position + Origin.position) : _data.holdingEntity.GetPosition();
|
||||
MinEventParams.CachedEventParam.Self = _data.holdingEntity;
|
||||
MinEventParams.CachedEventParam.Position = vector;
|
||||
MinEventParams.CachedEventParam.ItemValue = itemValue;
|
||||
itemValue.FireEvent(MinEventTypes.onProjectileImpact, MinEventParams.CachedEventParam);
|
||||
_data.gameManager.ExplosionServer(0, vector, World.worldToBlockPos(vector), Quaternion.identity, this.explosion, _data.holdingEntity.entityId, 0.1f, false, itemValue.Clone());
|
||||
this.activateHolding(itemValue, 0, _data.model);
|
||||
_data.holdingEntity.inventory.DecHoldingItem(1);
|
||||
return;
|
||||
}
|
||||
_data.Changed();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnHoldingReset(ItemInventoryData _data)
|
||||
{
|
||||
_data.itemValue.Meta = 0;
|
||||
this.setActivationTransformsActive(_data.holdingEntity.inventory.models[_data.holdingEntity.inventory.holdingItemIdx], false);
|
||||
}
|
||||
|
||||
private void activateHolding(ItemValue iv, int ticks, Transform _t)
|
||||
{
|
||||
iv.Meta = ticks;
|
||||
if (_t != null)
|
||||
{
|
||||
OnActivateItemGameObjectReference component = _t.GetComponent<OnActivateItemGameObjectReference>();
|
||||
if (component != null)
|
||||
{
|
||||
bool flag = ticks != 0;
|
||||
if (component.IsActivated() != flag)
|
||||
{
|
||||
component.ActivateItem(flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnDroppedUpdate(ItemWorldData _data)
|
||||
{
|
||||
EntityItem entityItem = _data.entityItem;
|
||||
bool flag = _data.world.IsRemote();
|
||||
ItemValue itemValue = entityItem.itemStack.itemValue;
|
||||
if (itemValue.Meta == 65535)
|
||||
{
|
||||
itemValue.Meta = -1;
|
||||
}
|
||||
Vector3 vector = entityItem.PhysicsMasterGetFinalPosition();
|
||||
MinEventParams.CachedEventParam.Position = vector;
|
||||
|
||||
if (!flag && this.bExplodeOnHitGround && (!this.mustPrime || itemValue.Meta > 0) && (entityItem.isCollided || _data.world.IsWater(vector)))
|
||||
{
|
||||
itemValue.FireEvent(MinEventTypes.onProjectileImpact, new MinEventParams
|
||||
{
|
||||
Self = (_data.world.GetEntity(_data.belongsEntityId) as EntityAlive),
|
||||
IsLocal = true,
|
||||
Position = vector,
|
||||
ItemValue = itemValue
|
||||
});
|
||||
itemValue.Meta = 1;
|
||||
}
|
||||
if (!flag && ((this.dropStarts && itemValue.Meta == 0) || (this.mustPrime && itemValue.Meta <= -1)))
|
||||
{
|
||||
itemValue.Meta = this.explodeAfterTicks;
|
||||
}
|
||||
if (itemValue.Meta > 0)
|
||||
{
|
||||
OnActivateItemGameObjectReference onActivateItemGameObjectReference = (entityItem.GetModelTransform() != null) ? entityItem.GetModelTransform().GetComponent<OnActivateItemGameObjectReference>() : null;
|
||||
if (onActivateItemGameObjectReference != null && !onActivateItemGameObjectReference.IsActivated())
|
||||
{
|
||||
onActivateItemGameObjectReference.ActivateItem(true);
|
||||
this.setActivationTransformsActive(entityItem.GetModelTransform(), true);
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.tickSoundDelay -= 0.05f;
|
||||
if (this.tickSoundDelay <= 0f)
|
||||
{
|
||||
this.tickSoundDelay = entityItem.itemClass.SoundTickDelay;
|
||||
entityItem.PlayOneShot(entityItem.itemClass.SoundTick, false);
|
||||
}
|
||||
itemValue.Meta--;
|
||||
if (itemValue.Meta == 0)
|
||||
{
|
||||
entityItem.SetDead();
|
||||
_data.gameManager.ExplosionServer(0, vector, World.worldToBlockPos(vector), Quaternion.identity, this.explosion, _data.belongsEntityId, 0f, false, itemValue.Clone());
|
||||
return;
|
||||
}
|
||||
entityItem.itemStack.itemValue = itemValue;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnDamagedByExplosion(ItemWorldData _data)
|
||||
{
|
||||
_data.gameManager.ExplosionServer(0, _data.entityItem.GetPosition(), World.worldToBlockPos(_data.entityItem.GetPosition()), Quaternion.identity, this.explosion, _data.belongsEntityId, _data.entityItem.rand.RandomRange(0.1f, 0.3f), false, _data.entityItem.itemStack.itemValue.Clone());
|
||||
}
|
||||
|
||||
public override bool CanCollect(ItemValue _iv)
|
||||
{
|
||||
return _iv.Meta == 0;
|
||||
}
|
||||
|
||||
private void setActivationTransformsActive(Transform item, bool isActive)
|
||||
{
|
||||
foreach (string name in this.activationTransformToHide)
|
||||
{
|
||||
Transform transform = item.FindInChilds(name, false);
|
||||
if (transform != null)
|
||||
{
|
||||
transform.gameObject.SetActive(isActive);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool bExplodeOnHitGround;
|
||||
private const int cPrimed = -1;
|
||||
private ExplosionData explosion;
|
||||
private bool dropStarts;
|
||||
private bool mustPrime;
|
||||
private int explodeAfterTicks;
|
||||
private float tickSoundDelay;
|
||||
private string[] activationTransformToHide = new string[0];
|
||||
}
|
||||
Reference in New Issue
Block a user