Пример #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);
            }
        }
Пример #2
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);
            }
        }
Пример #3
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);
                });
            }
        }
Пример #4
0
        public State(CompositeDisposable cd, IEngine engine)
        {
            NextId               = engine.El(1);
            CreateNewItem        = engine.MultiOp <string>();
            Items                = engine.Li(new List <ITodoItem>());
            ToggleItemComplete   = engine.MultiOp <string>();
            UncompletedCount     = engine.El(0);
            DeleteCompletedItems = engine.Op <Empty>();
            DeleteItem           = engine.MultiOp <string>();
            EditItem             = engine.Op <string>();
            EditingItemId        = engine.El <string>(null);
            FinishEditItem       = engine.Op <string>();
            ItemFactory          = new TodoItem.Factory(cd, engine,
                                                        ToggleItemComplete, EditingItemId, FinishEditItem);

            engine.Computer(cd,
                            new object[] {
                Items,
                ToggleItemComplete,
            },
                            () => Computers.UncompletedCount(
                                UncompletedCount,
                                Items
                                )
                            );

            engine.Computer(cd,
                            new object[]
            {
                CreateNewItem,
                DeleteCompletedItems,
                DeleteItem
            },
                            () => Computers.Items(
                                Items,
                                NextId,
                                CreateNewItem,
                                DeleteCompletedItems,
                                DeleteItem,
                                ItemFactory
                                )
                            );

            engine.Computer(cd,
                            new object[]
            {
                EditItem,
                FinishEditItem
            },
                            () => Computers.EditingItemId(
                                EditingItemId,
                                EditItem,
                                FinishEditItem
                                )
                            );
        }
Пример #5
0
 public DamageHitter(IEngine engine, Info.DamageHitter info)
     : base(info)
 {
     this.info        = info;
     Subtract         = engine.El(info.Subtract);
     PureChance       = engine.El(info.PureChance);
     CriticalChance   = engine.El(info.CriticalChance);
     LifeStealPercent = engine.El(info.LifeStealPercent);
     DotSpeed         = engine.El(info.DotSpeed);
 }
Пример #6
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);
                    }
                }
            }
Пример #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);
            }
        }
Пример #8
0
            public Factory(
                CompositeDisposable cd,
                IEngine engine,
                IMultiOp <string> toggleComplete,
                IEl <string> editingItemId,
                IOp <string> finishEdit
                )
            {
                this.engine         = engine;
                this.toggleComplete = toggleComplete;
                this.editingItemId  = editingItemId;
                this.finishEdit     = finishEdit;

                cd.Add(this);
            }
Пример #9
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);
            }
        }
Пример #10
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);
            }
        }
Пример #11
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);
                }
            }
Пример #12
0
        public State(CompositeDisposable cd, IEngine engine)
        {
            Value    = engine.El(0);
            Increase = engine.MultiOp <Empty>();
            Decrease = engine.MultiOp <Empty>();

            engine.Computer(cd,
                            new object[] {
                Increase,
                Decrease
            },
                            () => Computers.Value(
                                Value,
                                Increase,
                                Decrease
                                )
                            );
        }
Пример #13
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);
            }
        }
Пример #14
0
        public TodoItem(
            CompositeDisposable cd,
            IEngine engine,
            IMultiOp <string> toggleComplete,
            IEl <string> editingItemId,
            IOp <string> finishEdit,
            string id,
            string content)
        {
            this.id      = id;
            this.content = engine.El(content);
            isCompleted  = engine.El(false);

            cd = new CompositeDisposable();

            engine.Computer(cd,
                            new object[] {
                toggleComplete
            },
                            () => Computers.TodoItem.IsCompleted(
                                isCompleted,
                                toggleComplete,
                                this.id
                                )
                            );

            engine.Computer(cd,
                            new object[] {
                editingItemId,
                finishEdit
            },
                            () => Computers.TodoItem.Content(
                                this.content,
                                editingItemId,
                                finishEdit,
                                this.id
                                )
                            );
        }
Пример #15
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);
            }
        }
Пример #16
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);
            }
        }
Пример #17
0
 public DamageReflector(IEngine engine, Info.DamageReflector info)
 {
     basePercent = info.Percent;
     Percent     = engine.El(basePercent);
 }
Пример #18
0
 public Spatial(IEngine engine, int face)
 {
     Position = engine.El <Vector3?>(null);
     Face     = engine.El(face);
 }
Пример #19
0
 public Item(IEngine engine, int value)
 {
     Value = engine.El(value);
 }
Пример #20
0
 public ModifierItem(IEngine engine, Info.IModifier info)
 {
     Info   = info;
     Remain = engine.El(info.Duration);
 }
Пример #21
0
 private void Start()
 {
     elementalBehaviour = new ElFire() as IEl;
 }
Пример #22
0
 public StickHitItem(IEngine engine, Ops.Hit hit)
 {
     Hit     = hit;
     Elapsed = engine.El(0);
 }
Пример #23
0
 public Health(IEngine engine, Info.Health info)
 {
     Max        = engine.El(info.Max);
     Current    = engine.El(info.Current);
     RegenSpeed = engine.El(info.RegenSpeed);
 }
Пример #24
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);
            }
        }
Пример #25
0
 public Team(IEngine engine, Info.Team info)
 {
     Value = engine.El(info.Value);
 }
Пример #26
0
 public Armor(IEngine engine, Info.Armor info)
 {
     baseValue = info.Value;
     Value     = engine.El(baseValue);
 }
Пример #27
0
        public RandomSeed(IEngine engine, int value)
        {
            rand = new Random(value);

            Value = engine.El(rand.Next());
        }