예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns>true == under construction</returns>
        public bool NextRound()
        {
            Town t = _info.Town();

            foreach (KeyValuePair <string, int> cost in _data.construction.ToDictionary(entry => entry.Key, entry => entry.Value))
            {
                //buildtime?
                if (cost.Key == C.BuildRes)
                {
                    continue;
                }

                //normal ress?
                if (t.GetRes(cost.Key) >= cost.Value)
                {
                    t.AddRes(cost.Key, -cost.Value, ResType.Construction);
                    _data.construction.Remove(cost.Key);
                }
                else if (t.GetRes(cost.Key) >= 1)
                {
                    int val = t.GetRes(cost.Key);
                    _data.construction[cost.Key] -= val;
                    t.AddRes(cost.Key, -val, ResType.Construction);
                    _info.SetLastInfo($"Need {_data.construction[cost.Key]} more {L.b.res[cost.Key].Name()} for construction of {_data.name}.");
                }
                else
                {
                    _info.SetLastInfo($"Need {_data.construction[cost.Key]} more {L.b.res[cost.Key].Name()} for construction of {_data.name}.");
                }
            }

            //buildtime
            if (_data.construction[C.BuildRes] > 0)
            {
                _data.construction[C.BuildRes] -= 1;
                //set opacity
                GetComponent <SpriteRenderer>().color = new Color(GetConstructionProcent(), 1, GetConstructionProcent(), 0.5f + GetConstructionProcent() / 2);
            }

            //finish?
            if (_data.construction.Count == 1 && _data.construction[C.BuildRes] == 0)
            {
                _data.construction = null;
                _data.buildTime    = 0;
                _info.FinishConstruct();
                return(false);
            }

            return(true);
        }
예제 #2
0
        protected bool ProduceOneRes(ActionEvent evt, MapElementInfo info, NVector pos, int val, string res)
        {
            //Debug.Log(res+" "+val+" "+GameMgmt.Get().data.map.ResGenContains(pos, res));

            //remove?
            if (val > 0 && GameMgmt.Get().data.map.ResGenContains(pos, res))
            {
                int rval = GameMgmt.Get().data.map.ResGen(pos, res);
                if (rval < 200 && Random.Range(0, 200) > rval)
                {
                    val = 1;
                }

                if (rval <= 0)
                {
                    info.SetLastInfo(S.T("produceDepositEmpty", res));
                    return(false);
                }

                if (rval < 20)
                {
                    info.SetLastInfo(S.T("produceDepositNearlyEmpty", res));
                }

                GameMgmt.Get().data.map.ResGenAdd(pos, res, -val);
            }

            ResType r = evt == ActionEvent.NextRound ? ResType.Produce :
                        evt == ActionEvent.FinishConstruct ? ResType.Construction : ResType.Gift;

            double v = val;

            //add modi?
            if (r == ResType.Produce && val > 0)
            {
                v = L.b.modifiers[C.ProduceModi].CalcModi(v, info.Player(), info.Pos());
            }

            //todo right comb?
            info.Town().AddRes(res, v, r);

            return(true);
        }
예제 #3
0
        protected override void Perform(ActionEvent evt, Player player, MapElementInfo info, NVector pos,
                                        ActionHolder holder)
        {
            // show it
            if (evt == ActionEvent.Direct)
            {
                WindowBuilderSplit wbs = WindowBuilderSplit.Create("Craft", null);
                wbs.Add(new CraftStatusSplitElement(info, holder));

                //build it
                foreach (var craft in L.b.crafts.GetAllByCategory(holder.data["category"]))
                {
                    if (craft.req.Check(player, info, pos, true))
                    {
                        wbs.Add(new CraftSplitElement(craft, info, holder));
                    }
                }

                wbs.Finish();
                return;
            }

            //produce
            if (evt == ActionEvent.NextRound)
            {
                //has it?
                if (!holder.data.ContainsKey("craft0"))
                {
                    info.SetLastInfo("Nothing to craft");
                    return;
                }

                var c = SplitHelper.SplitInt(holder.data["craft0"]);

                //produce?
                Craft craft = L.b.crafts[c.key];

                foreach (var data in craft.res)
                {
                    if (!ProduceOneRes(evt, info, pos, data.Value, data.Key))
                    {
                        return;
                    }
                }

                //found it?
                if (c.value > 0)
                {
                    c.value--;
                    if (c.value > 0)
                    {
                        holder.data["craft0"] = SplitHelper.BuildSplit(c.key, c.value);
                    }
                    else
                    {
                        //delete it?
                        CraftMgmt.RebuildAfter(0, holder.data);
                    }
                }
            }
        }