Esempio n. 1
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            RPGCharacter character = (RPGCharacter)target;

            if (character.Buffs != null && character.Buffs.Count != 0)
            {
                foreach (Buff buff in character.Buffs)
                {
                    if (buff == null)
                    {
                        continue;
                    }

                    EditorGUI.indentLevel++;
                    EditorGUILayout.LabelField(buff.StackSize.Value.ToString() + "   " + buff.buffTemplate.name, EditorStyles.boldLabel);

                    Rect iconRect = GUILayoutUtility.GetLastRect();
                    iconRect      = EditorGUI.IndentedRect(iconRect);
                    iconRect.xMax = iconRect.xMin + iconRect.height;
                    iconRect.x   -= iconRect.height;

                    DrawCustomIcon(iconRect, buff.buffTemplate.Icon);

                    EditorGUI.indentLevel++;
                    foreach (BuffClock clock in buff.Clocks)
                    {
                        Rect rect = GUILayoutUtility.GetRect(0, 16);

                        rect = EditorGUI.IndentedRect(rect);

                        if (typeof(BuffClockDecaying).IsAssignableFrom(clock.GetType()))
                        {
                            BuffClockDecaying decayingClock = (BuffClockDecaying)clock;

                            EditorGUI.ProgressBar(rect, decayingClock.TimeRemaining / decayingClock.Duration, decayingClock.StackSize.Value.ToString());
                        }
                        else if (typeof(BuffClockFixed).IsAssignableFrom(clock.GetType()))
                        {
                            BuffClockFixed fixedClock = (BuffClockFixed)clock;

                            EditorGUI.ProgressBar(rect, 1.0f, fixedClock.StackSize.Value.ToString());
                        }
                    }

                    EditorGUI.indentLevel--;
                    EditorGUI.indentLevel--;
                }

                GUILayout.Space(20);
            }
        }
Esempio n. 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;
                }
            };
        }