示例#1
0
            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;
                double param = 0;

                foreach (var obj in args)
                {
                    if (obj is double || obj is long || obj is int)
                    {
                        param += Convert.ToDouble(obj);
                    }
                }
                var fromEnergy = param * Life.World.Random.NextDouble();
                var substance  = new Substance(
                    Life.World,
                    /*to Energy*/ fromEnergy * (param * (0.95 + 0.06 / (Life.World.Random.NextDouble() - 1.065))),
                    fromEnergy
                    );
                var energy = Life.Energy * (-0.06 / (Life.World.Random.NextDouble() - 1.065));
                var v      = Math.Tan(0.89 * Math.PI * (Life.World.Random.NextDouble() - 0.49)) * 7 + 50;
                var min    = (Math.Tan(0.85 * Math.PI * (Life.World.Random.NextDouble() - 0.466)) / 10 + 0.3) * 0.5 + 0.05;
                var amount = substance.FromEnergy * energy;
                var limit  = v * (Math.Tan(0.85 * Math.PI * (Life.World.Random.NextDouble() - 0.466)) / 10 + 0.3);
                var res    = new SubstanceCapsule(Life, substance, amount, min + v, min, limit);

                Life.AddResource(res);
            }
示例#2
0
            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 energy = this.Life.World.Random.NextDouble() * (res.TransferLimit.Value / res.Substance.FromEnergy);

                res.TransferFromEnergy(energy);
            }
示例#3
0
            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[0] is Substance)
                {
                    res = this.Life.Resources[args[0] as Substance];
                }
                else if (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;
            }
示例#4
0
            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;
                if (this.Life.SubstanceCapsuleList.Count <= 0)
                {
                    return;
                }
                SubstanceCapsule res1 = null;
                SubstanceCapsule res2 = null;

                for (var i = 0; i < args.Length; i++)
                {
                    if (res1 == null)
                    {
                        if (args[i] is SubstanceCapsule)
                        {
                            res1 = args[i] as SubstanceCapsule;
                        }
                        else if (args[i] is SubstanceCapsule)
                        {
                            res1 = args[i] as SubstanceCapsule;
                        }
                    }
                    else if (res2 == null)
                    {
                        if (args[i] is SubstanceCapsule)
                        {
                            res2 = this.Life.Resources[args[i] as Substance];
                        }
                        else if (args[i] is SubstanceCapsule)
                        {
                            res2 = args[i] as SubstanceCapsule;
                        }
                    }
                }
                if (res1 == null)
                {
                    res1 = this.Life.SubstanceCapsuleList.GetRandom();
                }
                if (res2 == null)
                {
                    res2 = this.Life.SubstanceCapsuleList.GetRandom();
                }
                double amount = this.Life.World.Random.NextDouble() * res1.TransferLimit.Value;

                amount = res1.TransferTo(res2, amount);
            }
示例#5
0
            public override void Act(params object[] args)
            {
                if (Life.Energy < this.EnergyCost)
                {
                    this.Life.Stimulate(this.Life.EnergyLowStimulus);
                    return;
                }
                Life.Energy -= this.EnergyCost;
                double           param     = 0;
                Substance        substance = null;
                SubstanceCapsule res       = null;

                foreach (object obj in args)
                {
                    if (obj is double || obj is long || obj is int)
                    {
                        param += Convert.ToDouble(obj);
                    }
                    else if (substance == null)
                    {
                        if (obj is Substance)
                        {
                            substance = obj as Substance;
                        }
                        else if (obj is SubstanceCapsule)
                        {
                            substance = (obj as SubstanceCapsule).Substance;
                        }
                    }
                }
                if (substance == null || !Life.Resources.ContainsKey(substance))
                {
                    if (Life.Resources.Count <= 0)
                    {
                        return;
                    }
                    substance = Life.SubstanceCapsuleList.GetRandom().Substance;
                }

                res = Life.Resources[substance];
                var amount = res.TransferLimit * Math.Tan(0.85 * Math.PI * (Life.World.Random.NextDouble() - 0.49)) / 10 + 0.5;

                amount = res.Take(amount);
                Life.World[Life.X, Life.Y].Add(substance, amount);
            }
示例#6
0
            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;
                }
            }
示例#7
0
            public override void Act(params object[] args)
            {
                if (Life.Energy < this.EnergyCost)
                {
                    this.Life.Stimulate(this.Life.EnergyLowStimulus);
                    return;
                }

                Life.Energy = Life.Energy - this.EnergyCost;
                double        param     = 0;
                Substance     substance = null;
                SubstanceCell resCell   = null;

                foreach (object obj in args)
                {
                    if (obj is double || obj is long || obj is int)
                    {
                        param += Convert.ToDouble(obj);
                    }
                    else if (substance == null)
                    {
                        if (obj is Substance)
                        {
                            substance = obj as Substance;
                        }
                        else if (obj is SubstanceCapsule)
                        {
                            substance = (obj as SubstanceCapsule).Substance;
                        }
                        else if (obj is SubstanceCell)
                        {
                            substance = (obj as SubstanceCell).Substance;
                        }
                    }
                }
                var cell = Life.World[Life.X, Life.Y];

                if ((substance == null || !cell.Substances.ContainsKey(substance)) && cell.Substances.Count > 0)
                {
                    substance = cell.Substances.Keys.ToArray()[(int)((param * Life.World.Random.NextDouble()) % 1) * cell.Substances.Count];
                }

                if (substance == null || !cell.Substances.ContainsKey(substance))
                {
                    return;
                }

                resCell = cell.Substances[substance];
                double amount = 0;

                // create SubstanceCapsule
                if (!Life.Resources.Keys.Contains(substance))
                {
                    var v     = ((Math.Tan(0.85 * Math.PI * (Life.World.Random.NextDouble() - 0.466)) / 10) * 500 + 200);
                    var min   = ((Math.Tan(0.85 * Math.PI * (Life.World.Random.NextDouble() - 0.466)) / 10 + 0.3) * 0.5 + 0.05);
                    var limit = v * (Math.Tan(0.85 * Math.PI * (Life.World.Random.NextDouble() - 0.49)) / 10 + 0.3);
                    amount = limit * (Math.Tan(0.85 * Math.PI * (Life.World.Random.NextDouble() - 0.49)) / 10 + 0.5);
                    amount = cell.GetSubstance(substance, amount);
                    var res = new SubstanceCapsule(Life, substance, amount, min + v, min, limit);
                    Life.AddResource(res);
                }
                else
                {
                    var res = Life.Resources[substance];
                    amount = res.TransferLimit * (Math.Tan(0.85 * Math.PI * (Life.World.Random.NextDouble() - 0.49)) / 10 + 0.5);
                    amount = cell.GetSubstance(substance, amount);
                    res.Add(amount);
                }
            }