Ejemplo n.º 1
0
        public void Add(Address agentAddress, AgentGoldModifier modifier)
        {
            // FIXME: 다른 Add() 오버로드와 겹치는 로직이 아주 많음.
            if (modifier is null || modifier.IsEmpty)
            {
                return;
            }

            if (agentAddress.Equals(_agentGoldModifierInfo.Address))
            {
                var modifiers = _agentGoldModifierInfo.Modifiers;
                if (TryGetSameTypeModifier(modifier, modifiers, out var outModifier))
                {
                    outModifier.Add(modifier);
                    if (outModifier.IsEmpty)
                    {
                        modifiers.Remove(outModifier);
                    }
                }
                else
                {
                    modifiers.Add(modifier);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Modify the agent's gold.
        /// </summary>
        /// <param name="agentAddress"></param>
        /// <param name="gold"></param>
        public static void ModifyAgentGold(Address agentAddress, FungibleAssetValue gold)
        {
            if (gold.Sign == 0)
            {
                return;
            }

            var modifier = new AgentGoldModifier(gold);

            LocalLayer.Instance.Add(agentAddress, modifier);

            //FIXME Avoid LocalLayer duplicate modify gold.
            var state = new GoldBalanceState(agentAddress, Game.Game.instance.Agent.GetBalance(agentAddress, gold.Currency));

            if (!state.address.Equals(agentAddress))
            {
                return;
            }

            States.Instance.SetGoldBalanceState(state);
        }
Ejemplo n.º 3
0
        public void ModifyTest()
        {
            Assert.True(_goldBalanceState.Gold.Equals(new FungibleAssetValue(_currency)));
            var fav       = new FungibleAssetValue(_currency, 100, 0);
            var modifier  = new AgentGoldModifier(fav);
            var beforeFav = _goldBalanceState.Gold;

            _goldBalanceState = modifier.Modify(_goldBalanceState);
            Assert.True(_goldBalanceState.Gold.Equals(beforeFav + fav));

            fav               = new FungibleAssetValue(_currency, -100, 0);
            modifier          = new AgentGoldModifier(fav);
            beforeFav         = _goldBalanceState.Gold;
            _goldBalanceState = modifier.Modify(_goldBalanceState);
            Assert.True(_goldBalanceState.Gold.Equals(beforeFav + fav));

            fav               = new FungibleAssetValue(_currency, -100, 0);
            modifier          = new AgentGoldModifier(fav);
            beforeFav         = _goldBalanceState.Gold;
            _goldBalanceState = modifier.Modify(_goldBalanceState);
            Assert.True(_goldBalanceState.Gold.Equals(beforeFav + fav));
        }