private void OnHarvest(Harvestable.Harvest.ReceivedRequest request)
        {
            var   payload   = request.Payload;
            var   nowHealth = health.Data.CurrentHealth;
            float resTaken  = 0;

            if (nowHealth > payload.ResourcesNeed)
            {
                resTaken   = payload.ResourcesNeed;
                nowHealth -= payload.ResourcesNeed;
            }
            else
            {
                resTaken  = nowHealth;
                nowHealth = 0;
            }

            var update = new HarvestResponse()
            {
                ResourcesTaken = resTaken
            };

            cmdReceiver.SendHarvestResponse(request.RequestId, update);
            //Debug.Log("OnHarvest ResourceNeed<"+payload.ResourcesNeed+"> Harvester<"+payload.Harvester.Id+">");

            var update2 = new Health.Update
            {
                CurrentHealth = nowHealth
            };

            health.SendUpdate(update2);
        }
Beispiel #2
0
 private void SendHealthUpdate(int value)
 {
     Health.Update update = new Health.Update
     {
         Health = value
     };
     healthWriter.SendUpdate(update);
 }
Beispiel #3
0
        public static void SetCanBeChanged(this HealthWriter health, bool canBeChanged)
        {
            var update = new Health.Update()
            {
                CanBeChanged = canBeChanged
            };

            health.SendUpdate(update);
        }
Beispiel #4
0
        private void TakeDamageFromFire()
        {
            var update = new Health.Update()
            {
                CurrentHealth = health.Data.CurrentHealth - SimulationSettings.FireDamagePerTick
            };

            health.SendUpdate(update);
        }
Beispiel #5
0
 public static void SetCurrentHealth(this HealthWriter health, int newHealth)
 {
     if (health.Data.CanBeChanged)
     {
         var update = new Health.Update()
         {
             CurrentHealth = Mathf.Max(newHealth, 0)
         };
         health.SendUpdate(update);
     }
 }
Beispiel #6
0
    public void newBorn()
    {
        // 如果是儿童,一些属性要适当缩小
        float ratioChild = 1.0f;

        if (age.Data.Age < age.Data.GrowUpAge)
        {
            ratioChild = SimulationSettings.NPCChildhoodMinWeekness;
        }

        var update = new DinoAttrs.Update
        {
            IsDead            = false,
            OriginalAgression = ScriptableAnimalStats.agression,
            OriginalDominance = ScriptableAnimalStats.dominance,
            OriginalScent     = ScriptableAnimalStats.scent,
            OriginPosition    = transform.position.ToVector3f(),
            LastHatchTime     = 0,
            CurrentFood       = Random.Range(ScriptableAnimalStats.foodStorage * SimulationSettings.NPCOriginalMinFoodRate * ratioChild, ScriptableAnimalStats.foodStorage * ratioChild), // 儿童
            MaxFood           = ScriptableAnimalStats.foodStorage * ratioChild,                                                                                                           // 儿童
            Power             = ScriptableAnimalStats.power * ratioChild,                                                                                                                 // 儿童
            LiveCost          = ScriptableAnimalStats.liveCost * ratioChild,                                                                                                              // 儿童
        };

        attrsWriter.SendUpdate(update);

        // 小恐龙的生命值也要打折扣
        var update3 = new Health.Update
        {
            CurrentHealth = ScriptableAnimalStats.toughness * ratioChild, // 儿童
            CanBeChanged  = true,
            MaxHealth     = ScriptableAnimalStats.toughness * ratioChild, // 儿童
        };

        health.SendUpdate(update3);
    }
Beispiel #7
0
        public static void AddCurrentHealthDelta(this HealthWriter health, int delta)
        {
            if (health.Data.CanBeChanged)
            {
                if (health.TryingToDecreaseHealthBelowZero(delta))
                {
                    return;
                }

                var update = new Health.Update()
                {
                    CurrentHealth = Mathf.Max(health.Data.CurrentHealth + delta, 0)
                };
                health.SendUpdate(update);
            }
        }
Beispiel #8
0
        public override void Enter()
        {
            // 进入这个状态的时候,要把树的血设置满
            var update = new Health.Update
            {
                CurrentHealth = SimulationSettings.TreeMaxHealth
            };

            health.SendUpdate(update);
            var update2 = new Flammable.Update
            {
                CanBeIgnited = true
            };

            flammable.SendUpdate(update2);

            flammable.OnUpdate += (OnFlammableUpdated);
            health.OnUpdate    += (OnHealthUpdated);
        }