Beispiel #1
0
        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();
        }
Beispiel #2
0
        protected override void OnSetup(IBehaviourContext context)
        {
            EventEntry applyInput = Apply[context];
            ConnectionEntry <RPGCharacter> targetInput    = Target[context];
            ConnectionEntry <float>        durationInput  = Duration[context];
            ConnectionEntry <int>          stackSizeInput = StackSize[context];

            IntegerStack.Modifier modifier = null;

            BuffClockDecaying refreshClock = null;

            applyInput.OnEventFired += () =>
            {
                if (targetInput.Value == null)
                {
                    return;
                }

                if (Mode == ApplyMode.AddNewBuff)
                {
                    BuffClock buffClock = new BuffClockDecaying(this, context);
                    modifier = buffClock.StackSize.AddFlatModifier(stackSizeInput.Value);

                    Buff buff = new Buff(BuffToApply, targetInput.Value, buffClock);

                    targetInput.Value.Buffs.Add(buff);
                }
                else if (Mode == ApplyMode.SeperateClock)
                {
                    BuffClock buffClock = new BuffClockDecaying(this, context);
                    modifier = buffClock.StackSize.AddFlatModifier(stackSizeInput.Value);

                    Buff buff = targetInput.Value.Buffs.Find(BuffToApply);

                    if (buff == null)
                    {
                        buff = new Buff(BuffToApply, targetInput.Value, buffClock);
                        targetInput.Value.Buffs.Add(buff);
                    }
                    else
                    {
                        buff.AddClock(buffClock);
                    }
                }
                else if (Mode == ApplyMode.Refresh || Mode == ApplyMode.RefreshAndAdd)
                {
                    Buff buff = targetInput.Value.Buffs.Find(BuffToApply);

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

                    if (refreshClock == null)
                    {
                        refreshClock = new BuffClockDecaying(this, context);
                        modifier     = refreshClock.StackSize.AddFlatModifier(stackSizeInput.Value);

                        buff.AddClock(refreshClock);

                        refreshClock.OnRemove += () =>
                        {
                            refreshClock = null;
                        };
                    }

                    refreshClock.TimeRemaining = refreshClock.Duration;

                    if (Mode == ApplyMode.RefreshAndAdd)
                    {
                        refreshClock.StackSize.AddFlatModifier(stackSizeInput.Value);
                    }
                }
                else if (Mode == ApplyMode.Add)
                {
                    Buff buff = targetInput.Value.Buffs.Find(BuffToApply);

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

                    if (refreshClock == null)
                    {
                        refreshClock = new BuffClockDecaying(this, context);
                        modifier     = refreshClock.StackSize.AddFlatModifier(stackSizeInput.Value);

                        buff.AddClock(refreshClock);

                        refreshClock.OnRemove += () =>
                        {
                            refreshClock = null;
                        };
                    }

                    refreshClock.StackSize.AddFlatModifier(stackSizeInput.Value);
                }
            };

            stackSizeInput.OnAfterChanged += () =>
            {
                if (Mode != ApplyMode.Refresh)
                {
                    return;
                }

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