Esempio n. 1
0
        public static Result Create(ref Building building)
        {
            List<KeyValuePair<string, string>> postData = new List<KeyValuePair<string, string>>();

            JsonPlan plan = new JsonPlan
            {
                creates = new List<JsonCreate>
                {
                    new JsonCreate
                    {
                        buildingid = building.BaseId,
                        rectangle = string.Format("{0},{1};{2},{3}", building.Location.Point.X, building.Location.Point.Y, building.Location.Width, building.Location.Length)
                    }
                }

            };
            postData.Add(new KeyValuePair<string, string>(
                "plan",
                JsonHelper.JavaScriptSerialize<JsonPlan>(plan)
            ));
            string strResult = RequestManager.SendRequest(MoveUrl, postData, true);

            JsonResultCreate jsonResultCreate = null;
            IJsonResult jr = (IJsonResult)jsonResultCreate;

            Result result = ResponseManager.ProcessResponse<JsonResultCreate>(strResult, out jr);
            if (result.Flag == ResultFlag.Success)
                building.BaseId = ((JsonResultCreate)jr).UserBuildings[0].UserBuildingId;

            return result;
        }
Esempio n. 2
0
        public static int AddExp(int exps,Point targetPoint,Item energeItem)
        {
            int count;
            int eachExp  = 5;
            if (exps % eachExp == 0) count = exps / eachExp;
            else count = exps / eachExp + 1;

            Building build = new Building
            {
                BaseId = 301,
                Location = new Rectangle
                {
                    Point = targetPoint,
                    Width = 4,
                    Length = 4
                }
            };
            int i = 0;
            for (; i < count; i++)
            {
                build.BaseId = 301;
                Result result = BuildingManager.Create(ref build);
                if (result.Flag == ResultFlag.EnergyNotEnough)
                {
                    Result energyResult = ItemManager.UseItem(energeItem);
                    if (energyResult.Flag == ResultFlag.Failed)
                    {
                        break;
                    }
                    else
                    {
                        i--; continue;
                    }
                }
                else if (result.Flag == ResultFlag.Failed)
                    break;

                Result desResult = null;

                for(int j=0;j<10;j++)
                {
                    desResult = BuildingManager.Destory(build);
                    if (desResult.Flag == ResultFlag.Success) break;
                }

                if (desResult == null||desResult.Flag != ResultFlag.Success) break;
            }

            return  i * eachExp;
        }
Esempio n. 3
0
        public static Result Gain(Building build)
        {
            string url = build.BuildingType == BuildingType.Gold ? GainGoldUrl : GainResourceUrl;

            List<KeyValuePair<string, string>> postData = new List<KeyValuePair<string, string>>();

            postData.Add(new KeyValuePair<string, string>(
                "bid",
                build.Id.ToString()
            ));

            string result = RequestManager.SendRequest(url, postData, true);

            return ResponseManager.ProcessResponse(result);
        }
Esempio n. 4
0
        public static Result Destory(Building building)
        {
            List<KeyValuePair<string, string>> postData = new List<KeyValuePair<string, string>>();

            JsonPlan plan = new JsonPlan
            {
                removes = new List<JsonRemove>
                {
                    new JsonRemove
                    {
                        userbuildingid = building.BaseId
                    }
                }

            };
            postData.Add(new KeyValuePair<string, string>(
                "plan",
                JsonHelper.JavaScriptSerialize<JsonPlan>(plan)
            ));

            string result = RequestManager.SendRequest(MoveUrl, postData, true);

            return ResponseManager.ProcessResponse(result);
        }
Esempio n. 5
0
 public static bool CheckIsGainable(Building build)
 {
     return build.State == BuildState.Gain;
 }
Esempio n. 6
0
        public static Building ParseBuilding(JsonBuilding jbuilding)
        {
            Building build = new Building
            {
                Id = jbuilding.UserBuildingId,
                Location = new Rectangle
                {
                    Point = ParsePoint(jbuilding.UserBuildingPoint),
                    Width = 3,
                    Length = 3
                },
                State = (BuildState)jbuilding.State,
                Level = jbuilding.BuildingLevel,
                Direction = BuildDirection.Normal,

                BuildingType = jbuilding.Seed >0? BuildingType.Food:BuildingType.Gold
            };
            return build;
        }
Esempio n. 7
0
        public static Result MoveBuilding(Building building, Point target)
        {
            List<KeyValuePair<string, string>> postData = new List<KeyValuePair<string, string>>();

            JsonPlan plan = new JsonPlan
            {
                moves = new List<JsonMove>
                {
                    new JsonMove
                    {
                        userbuildingid = building.Id,
                        rectangle = string.Format("{0},{1};{2},{3}", target.X, target.Y, building.Location.Width, building.Location.Length)
                    }
                },
                revolves = new List<JsonRevolve>
                {
                    new JsonRevolve
                    {
                        userbuildingid = building.Id,
                        showdirection = 0
                    }
                }
            };

            postData.Add(new KeyValuePair<string, string>(
                "plan",
                JsonHelper.JavaScriptSerialize<JsonPlan>(plan)
            ));

            string result = RequestManager.SendRequest(MoveUrl, postData, true);

            return ResponseManager.ProcessResponse(result);
        }