コード例 #1
0
        protected override void OnSetup(IBehaviourContext context)
        {
            EventEntry applyInput = Apply[context];
            ConnectionEntry <RPGCharacter> targetInput    = Target[context];
            ConnectionEntry <int>          stackSizeInput = StackSize[context];

            applyInput.OnEventFired += () =>
            {
                if (Mode == ApplyMode.Add)
                {
                    Buff      buff      = new Buff(this, context);
                    BuffClock buffClock = new BuffClockFixed(this, context);

                    buffClock.StackSize.AddFlatModifier(stackSizeInput.Value);

                    buff.AddClock(buffClock);

                    targetInput.Value.Buffs.Add(buff);
                }
                else if (Mode == ApplyMode.Stack)
                {
                    Buff buff = targetInput.Value.Buffs.Find(BuffToApply);

                    Debug.Log(BuffToApply.name);

                    if (buff == null)
                    {
                        buff = new Buff(this, context);

                        BuffClock buffClock = new BuffClockFixed(this, context);
                        buffClock.StackSize.AddFlatModifier(0);

                        buff.AddClock(buffClock);

                        targetInput.Value.Buffs.Add(buff);
                    }

                    buff.BaseStackSize.Value += stackSizeInput.Value;
                }
            };

            stackSizeInput.OnAfterChanged += () =>
            {
                return;

                // if (modifier != null)
                //	modifier.Value = stackSizeInput.Value;
            };
        }
コード例 #2
0
ファイル: BuffWhilstNode.cs プロジェクト: xJayLee/RPGCore
        protected override void OnSetup(IBehaviourContext context)
        {
            var targetInput = Target[context];
            var whilstInput = Whilst[context];
            ConnectionEntry <int> stackSizeInput = StackSize[context];

            bool isActive = false;

            Buff buff = null;

            IntegerStack.Modifier modifier = null;

            Action changeHandler = () =>
            {
                if (targetInput.Value == null)
                {
                    return;
                }

                if (whilstInput.Value)
                {
                    if (!isActive)
                    {
                        if (Mode == ApplyMode.Add)
                        {
                            buff = new Buff(this, context);
                            BuffClock buffClock = new BuffClockFixed(this, context);

                            modifier = buffClock.StackSize.AddFlatModifier(stackSizeInput.Value);

                            buff.AddClock(buffClock);

                            targetInput.Value.Buffs.Add(buff);
                        }
                        else
                        {
                            buff = targetInput.Value.Buffs.Find(BuffToApply);

                            if (buff == null)
                            {
                                buff = new Buff(this, context);
                                targetInput.Value.Buffs.Add(buff);
                            }

                            BuffClock buffClock = new BuffClockFixed(this, context);

                            modifier = buffClock.StackSize.AddFlatModifier(stackSizeInput.Value);

                            buff.AddClock(buffClock);
                        }
                        isActive = true;
                    }
                }
                else if (isActive)
                {
                    targetInput.Value.Buffs.Remove(buff);
                    isActive = false;
                }
                ;
            };

            targetInput.OnBeforeChanged += () =>
            {
                if (targetInput.Value == null)
                {
                    isActive = false;
                    return;
                }

                if (!isActive)
                {
                    return;
                }

                Debug.Log("Ending");
                targetInput.Value.Buffs.Remove(buff);
                isActive = false;
            };

            stackSizeInput.OnAfterChanged += () =>
            {
                if (modifier != null)
                {
                    modifier.Value = stackSizeInput.Value;
                }
            };

            targetInput.OnAfterChanged += changeHandler;
            whilstInput.OnAfterChanged += changeHandler;

            changeHandler();
        }