public override void Act(params object[] args) { if (this.Life.Energy < this.EnergyCost.Value) { this.Life.Stimulate(this.Life.EnergyLowStimulus); return; } this.Life.Energy -= this.EnergyCost; SubstanceCapsule res = null; if (args.Length > 0 && args[0] is Substance) { res = this.Life.Resources[args[0] as Substance]; } else if (args.Length > 0 && args[0] is SubstanceCapsule) { res = args[0] as SubstanceCapsule; } else { if (this.Life.SubstanceCapsuleList.Count <= 0) { return; } res = this.Life.SubstanceCapsuleList.GetRandom(); } double amount = this.Life.World.Random.NextDouble() * res.TransferLimit.Value; var energy = res.TransferToEnergy(amount); this.Life.Energy += energy; }
public override void Act(params object[] args) { if (this.Life.Energy < this.EnergyCost.Value) { this.Life.Stimulate(this.Life.EnergyLowStimulus); return; } this.Life.Energy -= this.EnergyCost; SubstanceCapsule res = null; double rate = 0; foreach (var obj in args) { if (obj is SubstanceCapsule) { res = obj as SubstanceCapsule; } if (obj is double || obj is long || obj is int) { rate += Convert.ToDouble(obj); } } if (rate == 0) { rate = 1; } rate = (rate * Life.World.Random.NextDouble()) % 1.0; // cost resource if (res != null) { var energy = res.TransferToEnergy(res.Amount * rate); Life.Health.Value += energy; } //cost energy else { var energy = Life.Energy * rate; Life.Energy -= energy; Life.Health.Value += energy; } }