コード例 #1
0
ファイル: HumanNeedsEffect.cs プロジェクト: qmhoang/SKR
        protected override void OnTick(int apElapsed)
        {
            // todo need tuning
            int millisecondsElapsed = (int)Math.Round(World.ActionPointsToSeconds(apElapsed) * 1000);

            _staminaMSCount += millisecondsElapsed;
            _needsMSCount   += millisecondsElapsed;

            if (Holder.Entity.Has <Creature>())
            {
                var person = Holder.Entity.Get <Creature>();

                while (_staminaMSCount / StaminaRequirementInMS > 0)
                {
                    if (person.Stats["stat_energy"] > 0 &&
                        person.Stats["stat_food"] > 0 &&
                        person.Stats["stat_water"] > 0)
                    {
                        person.Stats["stat_stamina"].Value++;
                    }

                    _staminaMSCount -= StaminaRequirementInMS;
                }

                while (_needsMSCount / NeedsRequirementInMS > 0)
                {
                    person.Stats["stat_energy"].Value--;
                    person.Stats["stat_food"].Value--;
                    person.Stats["stat_water"].Value--;
                    person.Stats["stat_bladder"].Value--;

                    _needsMSCount -= NeedsRequirementInMS;
                }
            }
            else
            {
                Logger.WarnFormat("{0} doesn't have person component.", Identifier.GetNameOrId(Holder.Entity));
            }
        }
コード例 #2
0
ファイル: IntervalAction.cs プロジェクト: qmhoang/SKR
        public override ActionResult OnProcess()
        {
            var ts = new TimeSpan(0, 0, 0, 0, (int) Math.Round(World.ActionPointsToSeconds(APCost) * 1000));

            if (LengthInAP > APCost) {
                if (_counter > Interval) {
                    var result = OnInterval(Entity);

                    if (result == ActionResult.Aborted || result == ActionResult.Failed) {
                        return OnFinish(Entity);
                    } else if (result == ActionResult.SuccessNoTime) { // prevents infinite queuing
                        Entity.Get<ControllerComponent>().Enqueue(new IntervalAction(Entity, _counter - Interval + ts, Length - ts, Interval, OnInterval, OnFinish));
                        return ActionResult.Success;
                    } else {
                        Entity.Get<ControllerComponent>().Enqueue(new IntervalAction(Entity, _counter - Interval + ts, Length - ts, Interval, OnInterval, OnFinish));
                        return result;
                    }
                } else {
                    Entity.Get<ControllerComponent>().Enqueue(new IntervalAction(Entity, _counter + ts, Length - ts, Interval, OnInterval, OnFinish));
                    return ActionResult.Success;
                }
            }
            return OnFinish(Entity);
        }