Esempio n. 1
0
        /// <summary>
        /// 前往城镇
        /// </summary>
        /// <param name="fromIndex">From index.</param>
        /// <param name="toIndex">To index.</param>
        public void GoToCity(int fromIndex, int toIndex)
        {
            SceneData toScene = null;

            ModifyResources();
            db = OpenDb();
            string           indexToId = JsonManager.GetInstance().GetMapping <string>("SceneIndexToIds", toIndex.ToString());
            SqliteDataReader sqReader  = db.ExecuteQuery("select CityId from EnterCityTable where CityId == '" + indexToId + "' and BelongToRoleId = '" + currentRoleId + "'");

            if (sqReader.HasRows)
            {
                FloydResult result = floyd.GetResult(fromIndex, toIndex);
                //查询银子是否足够支付路费
                sqReader = db.ExecuteQuery("select Id, ResourcesData from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'");
                List <ResourceData> resources = null;
                if (sqReader.Read())
                {
                    string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData"));
                    resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr);
                    resources    = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourcesStr);
                    //查询目前的银子余额
                    ResourceData resource = resources.Find(re => re.Type == ResourceType.Silver);
                    if (resource != null)
                    {
                        if (resource.Num >= result.Distance)
                        {
                            resource.Num -= result.Distance;
                            //扣钱
                            db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "' where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id")));
                            toScene = JsonManager.GetInstance().GetMapping <SceneData>("Scenes", GetCityIdByIndex(toIndex));
                            Debug.LogWarning(GetCityIdByIndex(toIndex) + "," + toScene.Id + "," + toScene.Name);
                        }
                        else
                        {
                            AlertCtrl.Show("银子不够支付路费!");
                        }
                    }
                }
            }
            else
            {
                AlertCtrl.Show("并没有开启前方传送点!");
            }
            db.CloseSqlConnection();
            if (toScene != null)
            {
                Messenger.Broadcast <SceneData>(NotifyTypes.GoToCityEcho, toScene);
            }
        }
Esempio n. 2
0
 public void UpdateData(FloydResult result)
 {
     resultData = result;
 }