Exemplo n.º 1
0
        public static void ComputeRemain(IEl <int> target,
                                         IOp <Ops.Tick> tick)
        {
            int remain = target.Read();

            if (remain == 0)
            {
                return;
            }

            Ops.Tick t;
            if (tick.TryRead(out t))
            {
                remain -= t.Dt;
            }

            if (remain < 0)
            {
                remain = 0;
            }

            if (remain != target.Read())
            {
                target.Write(remain);
            }
        }
Exemplo n.º 2
0
        public static void Items(
            ILi <ITodoItem> target,
            IEl <int> nextId,
            IMultiOp <string> newItem_,
            IOp <Empty> deleteCompletedItems_,
            IMultiOp <string> deleteItem_,
            ITodoItemFactory factory)
        {
            var   newItem = newItem_.Read();
            Empty tmp;
            bool  deleteCompletedItems = deleteCompletedItems_.TryRead(out tmp);
            var   deleteItem           = deleteItem_.Read();

            if (newItem.Count <= 0 &&
                !deleteCompletedItems &&
                deleteItem.Count <= 0)
            {
                return;
            }

            var items = target.AsWrite();

            if (newItem.Count > 0)
            {
                for (int i = 0, n = newItem.Count; i < n; ++i)
                {
                    items.Add(factory.Create((nextId.Read() + i).ToString(), newItem[i]));
                }
                nextId.Write(nextId.Read() + newItem.Count);
            }

            if (deleteCompletedItems)
            {
                items.RemoveAll(it =>
                {
                    if (it.IsCompleted.Read())
                    {
                        factory.Dispose(it);
                        return(true);
                    }
                    return(false);
                });
            }

            if (deleteItem.Count > 0)
            {
                items.RemoveAll(it =>
                {
                    if (deleteItem.Contains(it.Id))
                    {
                        factory.Dispose(it);
                        return(true);
                    }
                    return(false);
                });
            }
        }
Exemplo n.º 3
0
        public static void ComputeElapsed(IEl <int> target,
                                          IOp <Ops.Tick> tick)
        {
            int elapsed = target.Read();

            Ops.Tick t;
            if (tick.TryRead(out t))
            {
                elapsed += t.Dt;
            }

            if (elapsed != target.Read())
            {
                target.Write(elapsed);
            }
        }
Exemplo n.º 4
0
        public static void ComputeValue(IEl <int> target, int baseValue,
                                        IList <IModifierItem> modifiers)
        {
            int add      = 0;
            int multiply = 0;

            for (int i = 0, n = modifiers.Count; i < n; ++i)
            {
                var m = modifiers[i];
                if (!(m.Info is Info.ArmorModifier))
                {
                    continue;
                }
                var a = (Info.ArmorModifier)m.Info;
                add      += a.Add;
                multiply += a.Multiply;
            }

            int value = baseValue;

            if (multiply != 0)
            {
                value *= multiply;
            }
            value += add;
            if (value != target.Read())
            {
                target.Write(value);
            }
        }
Exemplo n.º 5
0
            public static void IsCompleted(IEl <bool> target, IMultiOp <string> toggle_, string myId)
            {
                var toggle = toggle_.Read();

                var isCompleted = target.Read();

                for (int i = 0, n = toggle.Count; i < n; ++i)
                {
                    if (toggle[i] == myId)
                    {
                        isCompleted = !isCompleted;
                    }
                }
                if (isCompleted != target.Read())
                {
                    target.Write(isCompleted);
                }
            }
Exemplo n.º 6
0
        public static void EditingItemId(IEl <string> target, IOp <string> edit_, IOp <string> finish)
        {
            string edit;
            string tmp;
            var    editingItemId = target.Read();

            if (finish.TryRead(out tmp))
            {
                editingItemId = null;
            }
            else if (edit_.TryRead(out edit))
            {
                editingItemId = edit;
            }

            if (editingItemId != target.Read())
            {
                target.Write(editingItemId);
            }
        }
Exemplo n.º 7
0
        public static void Value(
            IEl <int> target,
            IMultiOp <Empty> inc,
            IMultiOp <Empty> dec
            )
        {
            int delta = inc.Read().Count - dec.Read().Count;

            if (delta != 0)
            {
                target.Write(target.Read() + delta);
            }
        }
Exemplo n.º 8
0
            public static void Content(IEl <string> target, IEl <string> editingItemId, IOp <string> finishEdit_, string myId)
            {
                string finishEdit;

                if (editingItemId.Read() == myId && finishEdit_.TryRead(out finishEdit))
                {
                    string newContent = finishEdit;
                    if (!string.IsNullOrEmpty(newContent))
                    {
                        target.Write(newContent);
                    }
                }
            }
Exemplo n.º 9
0
        public static void UncompletedCount(IEl <int> target, ILi <ITodoItem> items_)
        {
            var items            = items_.Read();
            int uncompletedCount = 0;

            for (int i = 0, n = items.Count; i < n; ++i)
            {
                if (!items[i].IsCompleted.Read())
                {
                    ++uncompletedCount;
                }
            }
            if (uncompletedCount != target.Read())
            {
                target.Write(uncompletedCount);
            }
        }
Exemplo n.º 10
0
        public static void ComputePercent(IEl <int> target, int basePercent,
                                          IList <IModifierItem> modifiers)
        {
            int add = 0;

            for (int i = 0, n = modifiers.Count; i < n; ++i)
            {
                var m = modifiers[i];
                if (!(m.Info is Info.DamageReflectorModifier))
                {
                    continue;
                }
                var a = (Info.DamageReflectorModifier)m.Info;
                add += a.AddPercent;
            }

            int percent = basePercent;

            percent += add;
            if (percent != target.Read())
            {
                target.Write(percent);
            }
        }
Exemplo n.º 11
0
        public static void ComputeCriticalChance(IEl <int> target, int baseCriticalChance,
                                                 IList <IModifierItem> modifiers)
        {
            int add = 0;

            for (int i = 0, n = modifiers.Count; i < n; ++i)
            {
                var m = modifiers[i];
                if (!(m.Info is Info.DamageCriticalChanceModifier))
                {
                    continue;
                }
                var a = (Info.DamageCriticalChanceModifier)m.Info;
                add += a.Add;
            }

            int criticalChance = baseCriticalChance;

            criticalChance += add;
            if (criticalChance != target.Read())
            {
                target.Write(criticalChance);
            }
        }
Exemplo n.º 12
0
        public static void ComputeCurrent(IEl <int> target,
                                          int max, int regenSpeed, IEntity entity, int armorValue,
                                          IOp <Ops.Tick> tick, IList <Ops.Hit> hit, IList <IStickHitItem> stickHits,
                                          int randomSeed)
        {
            if (target.Read() <= 0)
            {
                return;
            }

            int add = 0;
            int sub = 0;

            int ticks = 0;

            Ops.Tick t;
            if (tick.TryRead(out t))
            {
                ticks = t.Dt;
            }

            add += ticks * regenSpeed;

            for (int i = 0, n = hit.Count; i < n; ++i)
            {
                var h = hit[i];
                if (h.From.HasOwner.Owner != entity)
                {
                    continue;
                }

                var hitters = h.From.Hitters;
                if (hitters.Damage == null)
                {
                    continue;
                }

                int lifeStealPercent = hitters.Damage.LifeStealPercent.Read();
                if (lifeStealPercent <= 0)
                {
                    continue;
                }

                // TODO Still need hit random seed, beside world random seed
                // to make sure 2 hits in same update
                // are different when calc critical
                int dealtDamage = CalcDealtDamage(hitters.Damage,
                                                  h.To.Armor.Value.Read(), randomSeed, h.RandomSeed);
                int canStealAmount = Math.Min(dealtDamage, h.To.Health.Current.Read());
                add += (int)Math.Ceiling(canStealAmount * (lifeStealPercent / 100f));
            }

            for (int i = 0, n = stickHits.Count; i < n; ++i)
            {
                var s = stickHits[i];
                var h = s.Hit;
                if (h.From.HasOwner.Owner != entity)
                {
                    continue;
                }

                var hitters = h.From.Hitters;
                if (hitters.Damage == null)
                {
                    continue;
                }

                int lifeStealPercent = hitters.Damage.LifeStealPercent.Read();
                if (lifeStealPercent <= 0)
                {
                    continue;
                }

                int dealtDamage = CalcDealtDot(ticks, s, hitters.Damage,
                                               h.To.Armor.Value.Read(), randomSeed, h.RandomSeed);
                int canStealAmount = Math.Min(dealtDamage, h.To.Health.Current.Read());
                add += (int)Math.Ceiling(canStealAmount * (lifeStealPercent / 100f));
            }

            for (int i = 0, n = hit.Count; i < n; ++i)
            {
                var h = hit[i];
                if (h.To != entity)
                {
                    continue;
                }

                var hitters = h.From.Hitters;
                if (hitters.Damage == null)
                {
                    continue;
                }

                sub += CalcDealtDamage(hitters.Damage, armorValue,
                                       randomSeed, h.RandomSeed);
            }

            for (int i = 0, n = hit.Count; i < n; ++i)
            {
                var h = hit[i];
                if (h.From.HasOwner.Owner != entity)
                {
                    continue;
                }

                var reflectDamagePercent = h.To.DamageReflector.Percent.Read();
                if (reflectDamagePercent <= 0)
                {
                    continue;
                }

                var hitters = h.From.Hitters;
                if (hitters.Damage == null)
                {
                    continue;
                }

                int dealtDamage = CalcDealtDamage(hitters.Damage,
                                                  h.To.Armor.Value.Read(), randomSeed, h.RandomSeed);
                sub += (int)Math.Ceiling(dealtDamage * (reflectDamagePercent / 100f));
            }

            for (int i = 0, n = stickHits.Count; i < n; ++i)
            {
                var s = stickHits[i];
                var h = s.Hit;
                if (h.To != entity)
                {
                    continue;
                }

                var hitters = h.From.Hitters;
                if (hitters.Damage == null)
                {
                    continue;
                }

                sub += CalcDealtDot(ticks, s, hitters.Damage,
                                    armorValue, randomSeed, h.RandomSeed);
            }

            // Can be very flexible here, prefer add over sub, sub over add or fair
            int current = target.Read();

            current = Math.Min(max, current + add);
            current = Math.Max(0, current - sub);
            if (current != target.Read())
            {
                target.Write(current);
            }
        }