Ejemplo n.º 1
0
        /// <summary>
        /// 将修为添加给秘籍
        /// </summary>
        /// <param name="exp">Exp.</param>
        /// <param name="books">Books.</param>
        public void InsertExpIntoBooks(long exp, List <BookData> books)
        {
            db = OpenDb();
            SqliteDataReader sqReader;
            BookData         book;
            ExpData          expData;
            long             maxExp = Statics.GetBookMaxExp(QualityType.FlashRed);

            for (int i = 0, len = books.Count; i < len; i++)
            {
                book = books[i];
                if (!book.IsMindBook)
                {
                    sqReader = db.ExecuteQuery("select Id, ExpData from BookExpsTable where BookId = " + book.Id + " and BelongToRoleId = '" + currentRoleId + "'");
                    if (sqReader.Read())
                    {
                        expData = JsonManager.GetInstance().DeserializeObject <ExpData>(DESStatics.StringDecder(sqReader.GetString(sqReader.GetOrdinal("ExpData"))));
//                        expData.Cur = (long)Mathf.Clamp(expData.Cur + exp, 0, expData.Max);
                        expData.Cur = (long)Mathf.Clamp(expData.Cur + exp, 0, maxExp);
                        db.ExecuteQuery("update BookExpsTable set ExpData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(expData)) + "' where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id")));
                    }
                    else
                    {
                        db.ExecuteQuery("insert into BookExpsTable (BookId, ExpData, SecretsData, BelongToRoleId) values('" + book.Id + "', '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(new ExpData(exp, Statics.GetBookMaxExp(book.Quality)))) + "', '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(new List <SecretData>())) + "', '" + currentRoleId + "')");
                    }
                }
            }
            db.CloseSqlConnection();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 花费银子
        /// </summary>
        /// <returns><c>true</c>, if silver was cost, <c>false</c> otherwise.</returns>
        /// <param name="num">Number.</param>
        public bool CostSilver(double num)
        {
            if (num <= 0)
            {
                return(false);
            }
            bool hasEnoughSilver = false;

            db = OpenDb();
            SqliteDataReader sqReader = db.ExecuteQuery("select Id, ResourcesData from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'");

            if (sqReader.Read())
            {
                string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData"));
                resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr);
                List <ResourceData> resources = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourcesStr);
                //查询目前的银子余额
                ResourceData resource = resources.Find(re => re.Type == ResourceType.Silver);
                if (resource != null)
                {
                    if (resource.Num >= num)
                    {
                        hasEnoughSilver = true;
                        resource.Num   -= num;
                        //扣钱
                        db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "' where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id")));
                    }
                }
            }
            db.CloseSqlConnection();
            return(hasEnoughSilver);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 卸下秘籍
        /// </summary>
        /// <param name="id">Identifier.</param>
        public void UnuseBook(int id)
        {
            db = OpenDb();            //查询角色信息
            SqliteDataReader sqReader = db.ExecuteQuery("select RoleId, RoleData from RolesTable where RoleId = '" + currentRoleId + "' and BelongToRoleId = '" + currentRoleId + "'");

            if (sqReader.Read())
            {
                string roleId = sqReader.GetString(sqReader.GetOrdinal("RoleId"));
                //获取角色数据
                string roleDataStr = sqReader.GetString(sqReader.GetOrdinal("RoleData"));
                roleDataStr = roleDataStr.IndexOf("{") == 0 ? roleDataStr : DESStatics.StringDecder(roleDataStr);
                RoleData role = JsonManager.GetInstance().DeserializeObject <RoleData>(roleDataStr);
                sqReader = db.ExecuteQuery("select BookId from BooksTable where Id = " + id);
                if (sqReader.Read())
                {
                    string bookId = sqReader.GetString(sqReader.GetOrdinal("BookId"));
                    db.ExecuteQuery("update BooksTable set SeatNo = 888, BeUsingByRoleId = '' where Id = " + id);
                    int index = role.ResourceBookDataIds.FindIndex(item => item == bookId);
                    if (index >= 0)
                    {
                        //更新角色的秘籍信息
                        role.ResourceBookDataIds.RemoveAt(index);
                        db.ExecuteQuery("update RolesTable set RoleData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObjectDealVector(role)) + "' where RoleId = '" + roleId + "'");
                    }
                }
            }
            db.CloseSqlConnection();
            GetBooksListPanelData();
            CallRoleInfoPanelData(false);             //刷新队伍数据
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取行囊物品数据
        /// </summary>
        public void GetBagPanelData()
        {
            ModifyResources();
            List <ItemData> items     = new List <ItemData>();
            double          silverNum = 0;

            db = OpenDb();
            SqliteDataReader sqReader = db.ExecuteQuery("select Id, ItemId, Num from BagTable where BelongToRoleId = '" + currentRoleId + "'");
            ItemData         item;

            while (sqReader.Read())
            {
                item = JsonManager.GetInstance().GetMapping <ItemData>("ItemDatas", sqReader.GetString(sqReader.GetOrdinal("ItemId")));
                item.PrimaryKeyId = sqReader.GetInt32(sqReader.GetOrdinal("Id"));
                item.Num          = sqReader.GetInt32(sqReader.GetOrdinal("Num"));
                items.Add(item);
            }
            sqReader = db.ExecuteQuery("select 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)
                {
                    silverNum = resource.Num;
                }
            }
            db.CloseSqlConnection();
            Messenger.Broadcast <List <ItemData>, double>(NotifyTypes.GetBagPanelDataEcho, items, silverNum);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 是主角等级上升
        /// </summary>
        /// <param name="toLv">To lv.</param>
        public void HostRoleUpgrade(int toLv)
        {
            if (HostData.Lv >= toLv)
            {
                return;
            }
            RoleData role = null;

            db = OpenDb();
            SqliteDataReader sqReader = db.ExecuteQuery("select RoleData from RolesTable where RoleId = '" + currentRoleId + "'");
            string           roleDataStr;

            if (sqReader.Read())
            {
                roleDataStr = sqReader.GetString(sqReader.GetOrdinal("RoleData"));
                roleDataStr = roleDataStr.IndexOf("{") == 0 ? roleDataStr : DESStatics.StringDecder(roleDataStr);
                role        = JsonManager.GetInstance().DeserializeObject <RoleData>(roleDataStr);
                role.Lv     = toLv > role.Lv ? toLv : role.Lv;
                //更新主角数据
                db.ExecuteQuery("update RolesTable set RoleData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObjectDealVector(role)) + "' where RoleId = '" + currentRoleId + "'");
            }
            db.CloseSqlConnection();

            if (role != null)
            {
                HostData.MakeJsonToModel();
                role.MakeJsonToModel();
                Messenger.Broadcast <RoleData, RoleData>(NotifyTypes.HostRoleUpgradeEcho, HostData, role);
                CallRoleInfoPanelData(false); //刷新队伍数据
                MaiHandler.SetAccount(role);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 请求队伍信息面板数据
        /// </summary>
        public void CallRoleInfoPanelData(bool isfighting)
        {
            db = OpenDb();
            //正序查询处于战斗队伍中的角色
            SqliteDataReader sqReader = db.ExecuteQuery("select * from RolesTable where BelongToRoleId = '" + currentRoleId + "' and State = " + (int)RoleStateType.InTeam + " order by SeatNo");
            JObject          obj      = new JObject();
            JArray           data     = new JArray();
            string           roleId;
            string           roleDataStr;

            while (sqReader.Read())
            {
                roleId      = sqReader.GetString(sqReader.GetOrdinal("RoleId"));
                roleDataStr = sqReader.GetString(sqReader.GetOrdinal("RoleData"));
                roleDataStr = roleDataStr.IndexOf("{") == 0 ? roleDataStr : DESStatics.StringDecder(roleDataStr);
                data.Add(new JArray(
                             roleId,
                             roleDataStr,
                             sqReader.GetInt16(sqReader.GetOrdinal("State")),
                             sqReader.GetInt32(sqReader.GetOrdinal("InjuryType"))
                             ));
                //缓存主角数据
                if (roleId == currentRoleId)
                {
                    HostData        = JsonManager.GetInstance().DeserializeObject <RoleData>(roleDataStr);
                    HostData.Injury = (InjuryType)sqReader.GetInt32(sqReader.GetOrdinal("InjuryType"));
                }
            }
            obj["data"] = data;
            db.CloseSqlConnection();
            Messenger.Broadcast <JObject, bool>(NotifyTypes.CallRoleInfoPanelDataEcho, obj, isfighting);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 消耗资源
        /// </summary>
        /// <returns><c>true</c>, if resource was cost, <c>false</c> otherwise.</returns>
        /// <param name="type">Type.</param>
        /// <param name="num">Number.</param>
        public bool CostResource(ResourceType type, int num)
        {
            ModifyResources();
            bool result = false;

            db = OpenDb();
            SqliteDataReader    sqReader  = db.ExecuteQuery("select Id, ResourcesData from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'");
            List <ResourceData> resources = null;
            int id = 0;

            if (sqReader.Read())
            {
                id = sqReader.GetInt32(sqReader.GetOrdinal("Id"));
                string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData"));
                resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr);
                resources    = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourcesStr);
            }

            if (resources != null)
            {
                ResourceData find = resources.Find(item => item.Type == type);
                if (find != null && find.Num >= num)
                {
                    find.Num -= num;
                    db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "' where Id = " + id);
                    result = true;
                }
            }
            db.CloseSqlConnection();
            return(result);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 使用道具
        /// </summary>
        /// <param name="type">Type.</param>
        /// <param name="num">Number.</param>
        public void UseProp(PropType type, int num)
        {
            db = OpenDb();
            SqliteDataReader sqReader = db.ExecuteQuery("select Id, Data from GiftsTable where Type = " + (int)type + " and BelongToRoleId = '" + currentRoleId + "'");
            string           dataStr;
            PropData         propData;

            if (sqReader.Read())
            {
                dataStr      = DESStatics.StringDecder(sqReader.GetString(sqReader.GetOrdinal("Data")));
                propData     = JsonManager.GetInstance().DeserializeObject <PropData>(dataStr);
                propData.Num = Mathf.Clamp(propData.Num - num, 0, propData.Max);
                if (propData.Num > 0)
                {
                    //改
                    db.ExecuteQuery("update GiftsTable set Data = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(propData)) + "' where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id")));
                }
                else
                {
                    //删
                    db.ExecuteQuery("delete from GiftsTable where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id")));
                }
            }
            db.CloseSqlConnection();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 查询特定资源的数量
        /// </summary>
        /// <returns>The resource number.</returns>
        /// <param name="type">Type.</param>
        public double GetResourceNum(ResourceType type)
        {
            ModifyResources();
            double num = 0;

            db = OpenDb();
            SqliteDataReader    sqReader  = db.ExecuteQuery("select Id, ResourcesData from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'");
            List <ResourceData> resources = null;
            int id = 0;

            if (sqReader.Read())
            {
                id = sqReader.GetInt32(sqReader.GetOrdinal("Id"));
                string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData"));
                resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr);
                resources    = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourcesStr);
            }
            if (resources != null)
            {
                ResourceData find = resources.Find(item => item.Type == type);
                if (find != null)
                {
                    num = find.Num;
                }
            }
            db.CloseSqlConnection();
            return(num);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 遗忘秘籍诀要
        /// </summary>
        /// <param name="book">Book.</param>
        /// <param name="secret">Secret.</param>
        public void ForgetSecret(BookData book, SecretData secret)
        {
            List <SecretData> secrets = null;

            db = OpenDb();
            SqliteDataReader sqReader = db.ExecuteQuery("select Id, ExpData, SecretsData from BookExpsTable where BookId = " + book.Id + " and BelongToRoleId = '" + currentRoleId + "'");

            if (sqReader.Read())
            {
                secrets = JsonManager.GetInstance().DeserializeObject <List <SecretData> >(DESStatics.StringDecder(sqReader.GetString(sqReader.GetOrdinal("SecretsData"))));
                int findIndex = secrets.FindIndex(item => item.PrimaryKeyId == secret.PrimaryKeyId);
                if (findIndex >= 0)
                {
                    secrets.RemoveAt(findIndex);
                }
                db.ExecuteQuery("update BookExpsTable set SecretsData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(secrets)) + "' where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id")));
                db.ExecuteQuery("update BookSecretsTable set BelongToBookId = '' where Id = '" + secret.PrimaryKeyId + "'");
            }
            db.CloseSqlConnection();
            if (secrets != null)
            {
                Messenger.Broadcast <BookData, List <SecretData> >(NotifyTypes.DealSecretEcho, book, secrets);
                SoundManager.GetInstance().PushSound("ui0008");
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 回去商店数据
        /// </summary>
        /// <param name="storeId">Store identifier.</param>
        public void GetStoreData(string storeId)
        {
            ModifyResources();
            StoreData store = JsonManager.GetInstance().GetMapping <StoreData>("Stores", storeId);

            store.MakeJsonToModel();
            List <ItemData> items     = store.Items;
            double          silverNum = 0;

            db = OpenDb();
            SqliteDataReader    sqReader  = db.ExecuteQuery("select 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(item => item.Type == ResourceType.Silver);
                if (resource != null)
                {
                    silverNum = resource.Num;
                }
            }
            db.CloseSqlConnection();
            Messenger.Broadcast <List <ItemData>, double>(NotifyTypes.GetStorePanelDataEcho, items, silverNum);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 获取准备出发界面数据
        /// </summary>
        public void GetReadyToTravelPanelData()
        {
            ModifyResources();
            List <RoleData> roles = new List <RoleData>();
            UserData        user  = null;
            ItemData        food  = null;

            db = OpenDb();
            SqliteDataReader sqReader = db.ExecuteQuery("select * from RolesTable where State != " + ((int)RoleStateType.NotRecruited) + " and BelongToRoleId = '" + currentRoleId + "' order by State");
            RoleData         role;
            string           roleDataStr;

            while (sqReader.Read())
            {
                roleDataStr = sqReader.GetString(sqReader.GetOrdinal("RoleData"));
                roleDataStr = roleDataStr.IndexOf("{") == 0 ? roleDataStr : DESStatics.StringDecder(roleDataStr);
                role        = JsonManager.GetInstance().DeserializeObject <RoleData>(roleDataStr);
                role.MakeJsonToModel();
                role.PrimaryKeyId = sqReader.GetInt32(sqReader.GetOrdinal("Id"));
                role.State        = (RoleStateType)sqReader.GetInt32(sqReader.GetOrdinal("State"));
                role.Injury       = (InjuryType)sqReader.GetInt32(sqReader.GetOrdinal("InjuryType"));
                roles.Add(role);
            }
            sqReader = db.ExecuteQuery("select Data, AreaFoodNum from UserDatasTable where BelongToRoleId = '" + currentRoleId + "'");
            if (sqReader.Read())
            {
                user = JsonManager.GetInstance().DeserializeObject <UserData>(sqReader.GetString(sqReader.GetOrdinal("Data")));
                user.AreaFood.Num = sqReader.GetInt32(sqReader.GetOrdinal("AreaFoodNum"));
                if (user.AreaFood.Num < user.AreaFood.MaxNum)
                {
                    sqReader = db.ExecuteQuery("select * from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'");
                    if (sqReader.Read())
                    {
                        //更新
                        string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData"));
                        resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr);
                        List <ResourceData> resources = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourcesStr);
                        ResourceData        resource  = resources.Find(item => item.Type == ResourceType.Food);
                        double cutNum = (double)(user.AreaFood.MaxNum - user.AreaFood.Num);
                        cutNum = resource.Num >= cutNum ? cutNum : resource.Num;
                        if (cutNum > 0)
                        {
                            resource.Num      -= cutNum;
                            user.AreaFood.Num += (int)cutNum;
                        }
                    }
                }
                food = user.AreaFood;
            }
            db.CloseSqlConnection();
            if (roles.Count > 0 && food != null)
            {
                Messenger.Broadcast <List <RoleData>, UserData>(NotifyTypes.GetReadyToTravelPanelDataEcho, roles, user);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 领悟秘籍诀要
        /// </summary>
        /// <param name="secret">Secret.</param>
        public void StudySecret(BookData book, SecretData secret)
        {
            List <SecretData> secrets = null;

            db = OpenDb();
            SqliteDataReader sqReader = db.ExecuteQuery("select Id, ExpData, SecretsData from BookExpsTable where BookId = " + book.Id + " and BelongToRoleId = '" + currentRoleId + "'");

            if (sqReader.Read())
            {
                ExpData exp = JsonManager.GetInstance().DeserializeObject <ExpData>(DESStatics.StringDecder(sqReader.GetString(sqReader.GetOrdinal("ExpData"))));
                secrets = JsonManager.GetInstance().DeserializeObject <List <SecretData> >(DESStatics.StringDecder(sqReader.GetString(sqReader.GetOrdinal("SecretsData"))));
                int bookLv = Statics.GetBookLV(exp.Cur);
                if (secrets.Count >= bookLv)
                {
                    AlertCtrl.Show(string.Format("<color=\"{0}\">{1}</color>目前只能领悟最多{2}张诀要", Statics.GetQualityColorString(book.Quality), book.Name, bookLv));
                    db.CloseSqlConnection();
                    return;
                }
                else
                {
                    if (secrets.FindIndex(item => item.Type == secret.Type) < 0)
                    {
                        secrets.Add(secret);
                        db.ExecuteQuery("update BookExpsTable set SecretsData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(secrets)) + "' where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id")));
                        db.ExecuteQuery("update BookSecretsTable set BelongToBookId = '" + book.Id + "' where Id = '" + secret.PrimaryKeyId + "'");
                    }
                    else
                    {
                        AlertCtrl.Show("该类型诀要不能重复领悟!");
                        db.CloseSqlConnection();
                        return;
                    }
                }
            }
            else
            {
                secrets = new List <SecretData>()
                {
                    secret
                };
                //处理空数据初始化
                db.ExecuteQuery("insert into BookExpsTable (BookId, ExpData, SecretsData, BelongToRoleId) values('" + book.Id + "', '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(new ExpData(0, Statics.GetBookMaxExp(book.Quality)))) + "', '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(secrets)) + "', '" + currentRoleId + "')");
                db.ExecuteQuery("update BookSecretsTable set BelongToBookId = '" + book.Id + "' where Id = '" + secret.PrimaryKeyId + "'");
            }
            db.CloseSqlConnection();
            if (secrets != null)
            {
                Messenger.Broadcast <BookData, List <SecretData> >(NotifyTypes.DealSecretEcho, book, secrets);
                Statics.CreatePopMsg(Vector3.zero, string.Format("领悟<color=\"{0}\">{1}</color>后<color=\"{2}\">{3}</color>更为精进!!", Statics.GetQualityColorString(secret.Quality), secret.Name, Statics.GetQualityColorString(book.Quality), book.Name), Color.white, 30);
                SoundManager.GetInstance().PushSound("ui0010");
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 熔解兵器
        /// </summary>
        /// <param name="primaryKeyId">Primary key identifier.</param>
        public void BreakWeapon(int primaryKeyId)
        {
            int resultId = 0;

            db = OpenDb();
            //查询资源
            SqliteDataReader    sqReader  = db.ExecuteQuery("select Id, ResourcesData from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'");
            List <ResourceData> resources = null;
            int id = 0;

            if (sqReader.Read())
            {
                id = sqReader.GetInt32(sqReader.GetOrdinal("Id"));
                string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData"));
                resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr);
                resources    = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourcesStr);
            }
            if (resources != null)
            {
                sqReader = db.ExecuteQuery("select Id, WeaponId from WeaponsTable where Id = " + primaryKeyId);
                if (sqReader.Read())
                {
                    WeaponData   weapon = JsonManager.GetInstance().GetMapping <WeaponData>("Weapons", sqReader.GetString(sqReader.GetOrdinal("WeaponId")));
                    ResourceData findResource;
                    ResourceData resource;
                    float        addNum;
                    for (int i = 0; i < weapon.Needs.Count; i++)
                    {
                        resource     = weapon.Needs[i];
                        findResource = resources.Find(item => item.Type == resource.Type);
                        if (findResource != null)
                        {
                            addNum = Mathf.Floor((float)(resource.Num * 0.5f));
                            //累加资源
                            findResource.Num += addNum;
                        }
                    }
                    //删除兵器
                    db.ExecuteQuery("delete from WeaponsTable where Id = " + primaryKeyId);
                    //更新资源
                    db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "' where Id = " + id);
                    resultId = primaryKeyId;
                }
            }
            db.CloseSqlConnection();
            if (primaryKeyId > 0)
            {
                Messenger.Broadcast <int>(NotifyTypes.BreakWeaponEcho, primaryKeyId);
            }
        }
Ejemplo n.º 15
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);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 治疗侠客
        /// </summary>
        /// <param name="id">Identifier.</param>
        public void CureRole(int id)
        {
            db = OpenDb();
            SqliteDataReader sqReader = db.ExecuteQuery("select RoleData, InjuryType from RolesTable where Id = " + id);
            int      injury;
            bool     success = false;
            RoleData role    = null;

            if (sqReader.Read())
            {
                injury = sqReader.GetInt32(sqReader.GetOrdinal("InjuryType"));
                string roleDataStr = sqReader.GetString(sqReader.GetOrdinal("RoleData"));
                roleDataStr = roleDataStr.IndexOf("{") == 0 ? roleDataStr : DESStatics.StringDecder(roleDataStr);
                role        = JsonManager.GetInstance().DeserializeObject <RoleData>(roleDataStr);
                if (injury > 0)
                {
                    sqReader = db.ExecuteQuery("select Id, Num from BagTable where Type = " + ((int)ItemType.Vulnerary) + " and Lv >= " + injury + " and BelongToRoleId = '" + currentRoleId + "' order by Lv");
                    int primaryKeyId = 0;
                    int num          = 0;
                    if (sqReader.Read())
                    {
                        primaryKeyId = sqReader.GetInt32(sqReader.GetOrdinal("Id"));
                        num          = sqReader.GetInt32(sqReader.GetOrdinal("Num"));
                        if (num > 1)
                        {
                            db.ExecuteQuery("update BagTable set Num = " + (num - 1) + " where Id = " + primaryKeyId);
                        }
                        else
                        {
                            db.ExecuteQuery("delete from BagTable where Id = " + primaryKeyId);
                        }
                        db.ExecuteQuery("update RolesTable set InjuryType = " + ((int)InjuryType.None) + " where Id = " + id);
                        success = true;
                    }
                    else
                    {
                        AlertCtrl.Show(string.Format("行囊中并未发现有能够治愈{0}的伤药(需要{1}级伤药)", Statics.GetInjuryName((InjuryType)injury), injury), null);
                    }
                }
            }
            db.CloseSqlConnection();

            if (success && role != null)
            {
                Statics.CreatePopMsg(Vector3.zero, string.Format("<color=\"#FFFF00\">{0}</color>的伤势已经痊愈!", role.Name), Color.white, 30);
                GetHospitalPanelData();
                CallRoleInfoPanelData(false);                 //刷新队伍数据
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 获取秘籍的修为和已领悟的诀要集合
        /// </summary>
        /// <returns>The book exp and secrets.</returns>
        public ExpAndSecretData GetBookExpAndSecrets(string bookId)
        {
            ExpAndSecretData data = new ExpAndSecretData();

            db = OpenDb();
            SqliteDataReader sqReader = db.ExecuteQuery("select ExpData, SecretsData from BookExpsTable where BookId = '" + bookId + "' and BelongToRoleId = '" + currentRoleId + "'");

            if (sqReader.Read())
            {
                data.Exp     = JsonManager.GetInstance().DeserializeObject <ExpData>(DESStatics.StringDecder(sqReader.GetString(sqReader.GetOrdinal("ExpData"))));
                data.Secrets = JsonManager.GetInstance().DeserializeObject <List <SecretData> >(DESStatics.StringDecder(sqReader.GetString(sqReader.GetOrdinal("SecretsData"))));
            }
            db.CloseSqlConnection();
            return(data);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 查询道具诗句
        /// </summary>
        /// <returns>The property.</returns>
        /// <param name="type">Type.</param>
        public PropData GetProp(PropType type)
        {
            PropData propData = null;

            db = OpenDb();
            SqliteDataReader sqReader = db.ExecuteQuery("select Id, Data from GiftsTable where Type = " + (int)type + " and BelongToRoleId = '" + currentRoleId + "'");
            string           dataStr;

            if (sqReader.Read())
            {
                dataStr  = DESStatics.StringDecder(sqReader.GetString(sqReader.GetOrdinal("Data")));
                propData = JsonManager.GetInstance().DeserializeObject <PropData>(dataStr);
            }
            db.CloseSqlConnection();
            return(propData);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 查询可以领悟的所有诀要
        /// </summary>
        /// <returns>The effective secrets.</returns>
        public List <SecretData> GetEffectiveSecrets()
        {
            List <SecretData> secrets = new List <SecretData>();

            db = OpenDb();
            SqliteDataReader sqReader = db.ExecuteQuery("select * from BookSecretsTable where BelongToRoleId = '" + currentRoleId + "' and BelongToBookId = ''");
            SecretData       secret;

            while (sqReader.Read())
            {
                secret = JsonManager.GetInstance().DeserializeObject <SecretData>(DESStatics.StringDecder(sqReader.GetString(sqReader.GetOrdinal("SecretData"))));
                secret.PrimaryKeyId = sqReader.GetInt32(sqReader.GetOrdinal("Id"));
                secrets.Add(secret);
            }
            db.CloseSqlConnection();
            return(secrets);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 根据角色id查询角色数据
        /// </summary>
        /// <returns>The role data by role identifier.</returns>
        /// <param name="roleId">Role identifier.</param>
        public RoleData GetRoleDataByRoleId(string roleId)
        {
            RoleData data = null;

            db = OpenDb();
            SqliteDataReader sqReader = db.ExecuteQuery("select Id, RoleData, InjuryType from RolesTable where RoleId = '" + roleId + "' and State > 0 and BelongToRoleId = '" + currentRoleId + "'");

            if (sqReader.Read())
            {
                string roleDataStr = sqReader.GetString(sqReader.GetOrdinal("RoleData"));
                roleDataStr       = roleDataStr.IndexOf("{") == 0 ? roleDataStr : DESStatics.StringDecder(roleDataStr);
                data              = JsonManager.GetInstance().DeserializeObject <RoleData>(roleDataStr);
                data.PrimaryKeyId = sqReader.GetInt32(sqReader.GetOrdinal("Id"));
                data.Injury       = (InjuryType)sqReader.GetInt32(sqReader.GetOrdinal("InjuryType"));
            }
            db.CloseSqlConnection();
            return(data);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// 查询所有的道具
        /// </summary>
        /// <returns>The all properties.</returns>
        public List <PropData> GetAllProps()
        {
            List <PropData> props = new List <PropData>();

            db = OpenDb();
            SqliteDataReader sqReader = db.ExecuteQuery("select Data from GiftsTable where BelongToRoleId = '" + currentRoleId + "'");
            string           dataStr;
            PropData         propData;

            while (sqReader.Read())
            {
                dataStr  = DESStatics.StringDecder(sqReader.GetString(sqReader.GetOrdinal("Data")));
                propData = JsonManager.GetInstance().DeserializeObject <PropData>(dataStr);
                props.Add(propData);
            }
            db.CloseSqlConnection();
            return(props);
        }
Ejemplo n.º 22
0
        int modifyResourceTimeout    = 20;      //刷新资源间隔时间(单位:秒)

        /// <summary>
        /// 检测是否有新的生产单元
        /// </summary>
        /// <param name="cityId">City identifier.</param>
        public void CheckNewWorkshopItems(string cityId)
        {
            db = OpenDb();
            List <ResourceRelationshipData> resourcesRelationshipsInCity = WorkshopModel.Relationships.FindAll(item => item.BelongToCityId == cityId);

            if (resourcesRelationshipsInCity.Count > 0)
            {
                List <ResourceData> resources;
                SqliteDataReader    sqReader = db.ExecuteQuery("select * from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'");
                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);
                    for (int i = 0; i < resourcesRelationshipsInCity.Count; i++)
                    {
                        if (resources.FindIndex(item => item.Type == resourcesRelationshipsInCity[i].Type) < 0)
                        {
                            resources.Add(new ResourceData(resourcesRelationshipsInCity[i].Type, 0));
                        }
                    }
                    db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "' where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id")));
                }
                else
                {
                    //新增
                    resources = new List <ResourceData>();
                    for (int i = 0; i < resourcesRelationshipsInCity.Count; i++)
                    {
                        resources.Add(new ResourceData(resourcesRelationshipsInCity[i].Type, 0));
                    }
                    db.ExecuteQuery("insert into WorkshopResourceTable (ResourcesData, Ticks, WorkerNum, MaxWorkerNum, BelongToRoleId) values('" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "', " + DateTime.Now.Ticks + ", 0, 0, '" + currentRoleId + "')");
                }
                //记录当前所有的工坊资源类型列表
                CitySceneModel.ResourceTypeStrOfWorkShopNewFlagList = new List <string>();
                for (int i = resources.Count - 1; i >= 0; i--)
                {
                    CitySceneModel.ResourceTypeStrOfWorkShopNewFlagList.Add(resources[i].Type.ToString());
                }
            }
            db.CloseSqlConnection();
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 卸下兵器
        /// </summary>
        /// <param name="id">Identifier.</param>
        public void TakeOffWeapon(int id)
        {
            db = OpenDb();
            db.ExecuteQuery("update WeaponsTable set BeUsingByRoleId = '' where Id = " + id);
            SqliteDataReader sqReader = db.ExecuteQuery("select RoleId, RoleData from RolesTable where RoleId = '" + currentRoleId + "'");

            if (sqReader.Read())
            {
                //获取角色数据
                string roleDataStr = sqReader.GetString(sqReader.GetOrdinal("RoleData"));
                roleDataStr = roleDataStr.IndexOf("{") == 0 ? roleDataStr : DESStatics.StringDecder(roleDataStr);
                RoleData role = JsonManager.GetInstance().DeserializeObject <RoleData>(roleDataStr);
                role.ResourceWeaponDataId = "";
                //更新主角关联数据
                db.ExecuteQuery("update RolesTable set RoleData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObjectDealVector(role)) + "' where RoleId = '" + currentRoleId + "'");
            }
            db.CloseSqlConnection();
            GetWeaponsListPanelData();             //刷新兵器匣列表
            CallRoleInfoPanelData(false);          //刷新队伍数据
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 查询队伍中的侠客
        /// </summary>
        /// <returns>The roles in team.</returns>
        public List <RoleData> GetRolesInTeam()
        {
            List <RoleData> rolesData = new List <RoleData>();

            db = OpenDb();
            //正序查询处于战斗队伍中的角色
            SqliteDataReader sqReader = db.ExecuteQuery("select * from RolesTable where BelongToRoleId = '" + currentRoleId + "' and State = " + (int)RoleStateType.InTeam + " order by SeatNo");
            RoleData         roleData;
            string           roleDataStr;

            while (sqReader.Read())
            {
                roleDataStr     = sqReader.GetString(sqReader.GetOrdinal("RoleData"));
                roleDataStr     = roleDataStr.IndexOf("{") == 0 ? roleDataStr : DESStatics.StringDecder(roleDataStr);
                roleData        = JsonManager.GetInstance().DeserializeObject <RoleData>(roleDataStr);
                roleData.Injury = (InjuryType)((int)sqReader.GetInt32(sqReader.GetOrdinal("InjuryType")));
                rolesData.Add(roleData);
            }
            db.CloseSqlConnection();
            return(rolesData);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 请求医馆角色数据
        /// </summary>
        public void GetHospitalPanelData()
        {
            db = OpenDb();
            List <RoleData>  roles    = new List <RoleData>();
            SqliteDataReader sqReader = db.ExecuteQuery("select * from RolesTable where State != " + ((int)RoleStateType.NotRecruited) + " and BelongToRoleId = '" + currentRoleId + "'");
            RoleData         role;
            string           roleDataStr;

            while (sqReader.Read())
            {
                roleDataStr       = sqReader.GetString(sqReader.GetOrdinal("RoleData"));
                roleDataStr       = roleDataStr.IndexOf("{") == 0 ? roleDataStr : DESStatics.StringDecder(roleDataStr);
                role              = JsonManager.GetInstance().DeserializeObject <RoleData>(roleDataStr);
                role.PrimaryKeyId = sqReader.GetInt32(sqReader.GetOrdinal("Id"));
                role.State        = (RoleStateType)sqReader.GetInt32(sqReader.GetOrdinal("State"));
                role.Injury       = (InjuryType)sqReader.GetInt32(sqReader.GetOrdinal("InjuryType"));
                roles.Add(role);
            }
            db.CloseSqlConnection();
            Messenger.Broadcast <List <RoleData> >(NotifyTypes.GetHospitalPanelDataEcho, roles);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// 请求工坊主界面数据(包括生产材料标签页数据)
        /// </summary>
        public void GetWorkshopPanelData()
        {
            JArray data = new JArray();

            db = OpenDb();
            SqliteDataReader sqReader = db.ExecuteQuery("select * from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'");

            if (sqReader.Read())
            {
                string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData"));
                resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr);
                string resourceDataStr = resourcesStr;
                data.Add(sqReader.GetInt32(sqReader.GetOrdinal("Id")));
                data.Add(resourceDataStr);
//				data.Add(sqReader.GetInt32(sqReader.GetOrdinal("WorkerNum")));
//                data.Add(sqReader.GetInt32(sqReader.GetOrdinal("MaxWorkerNum")));
                data.Add(GetWorkerNum());
                data.Add(GetMaxWorkerNum());
                List <ResourceData> resultResources = returnAllReceiveResourcesOnece(resourceDataStr);
                data.Add(JsonManager.GetInstance().SerializeObject(resultResources));
            }
            db.CloseSqlConnection();
            Messenger.Broadcast <JArray>(NotifyTypes.GetWorkshopPanelDataEcho, data);
        }
Ejemplo n.º 27
0
        //将所有人的伤势缓解一级
        public void RelieveRoles()
        {
            db = OpenDb();
            bool             success  = false;
            RoleData         role     = null;
            SqliteDataReader sqReader = db.ExecuteQuery("select Id, RoleData, InjuryType from RolesTable where InjuryType > " + 0);
            string           roleDataStr;

            while (sqReader.Read())
            {
                roleDataStr = sqReader.GetString(sqReader.GetOrdinal("RoleData"));
                roleDataStr = roleDataStr.IndexOf("{") == 0 ? roleDataStr : DESStatics.StringDecder(roleDataStr);
                role        = JsonManager.GetInstance().DeserializeObject <RoleData>(roleDataStr);
                db.ExecuteQuery("update RolesTable set InjuryType = " + (sqReader.GetInt32(sqReader.GetOrdinal("InjuryType")) - 1) + " where Id = " + sqReader.GetInt32(sqReader.GetOrdinal("Id")));
                success = true;
            }
            db.CloseSqlConnection();
            if (success)
            {
                AlertCtrl.Show("各位侠客的伤势得到了缓解!");
                GetHospitalPanelData();
                CallRoleInfoPanelData(false); //刷新队伍数据
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// 打造兵器
        /// </summary>
        /// <param name="weaponId">Weapon identifier.</param>
        public void CreateNewWeaponOfWorkshop(string weaponId)
        {
            db = OpenDb();
            WeaponData          weapon = JsonManager.GetInstance().GetMapping <WeaponData>("Weapons", weaponId);
            List <ResourceData> needs  = new List <ResourceData>();
            ResourceData        need;
            ResourceData        find;

            for (int i = 0; i < weapon.Needs.Count; i++)
            {
                need = weapon.Needs[i];
                find = needs.Find(item => item.Type == need.Type);
                if (find == null)
                {
                    needs.Add(new ResourceData(need.Type, need.Num));
                }
                else
                {
                    find.Num += need.Num;
                }
            }
            SqliteDataReader    sqReader  = db.ExecuteQuery("select Id, ResourcesData from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'");
            List <ResourceData> resources = null;
            int id = 0;

            if (sqReader.Read())
            {
                id = sqReader.GetInt32(sqReader.GetOrdinal("Id"));
                string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData"));
                resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr);
                resources    = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourcesStr);
            }
            db.CloseSqlConnection();

            if (resources != null)
            {
                bool   canAdd = true;
                string msg    = "";
                for (int i = 0; i < needs.Count; i++)
                {
                    need = needs[i];
                    find = resources.Find(item => item.Type == need.Type);
                    if (find != null && find.Num >= need.Num)
                    {
                        find.Num -= need.Num;
                    }
                    else
                    {
                        canAdd = false;
                        msg    = string.Format("{0}不足!", Statics.GetResourceName(need.Type));
                        break;
                    }
                }
                if (canAdd)
                {
                    //检测添加武器
                    if (AddNewWeapon(weapon.Id))
                    {
                        db = OpenDb();
                        db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "' where Id = " + id);
                        db.CloseSqlConnection();
                        Statics.CreatePopMsg(Vector3.zero, string.Format("<color=\"{0}\">{1}</color>+1", Statics.GetQualityColorString(weapon.Quality), weapon.Name), Color.white, 30);
                        SoundManager.GetInstance().PushSound("ui0007");
                    }
                    else
                    {
                        AlertCtrl.Show("兵器匣已满!", null);
                    }
                }
                else
                {
                    AlertCtrl.Show(msg, null);
                }
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// 刷新资源数据
        /// </summary>
        public void ModifyResources()
        {
            JArray data = new JArray(modifyResourceTimeout, "[]", "[]");

            try {
                db = OpenDb();
                SqliteDataReader sqReader = db.ExecuteQuery("select * from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'");
                if (sqReader.Read())
                {
                    long     ticks       = sqReader.GetInt64(sqReader.GetOrdinal("Ticks"));
                    DateTime oldDate     = new DateTime(ticks);
                    float    skipSeconds = (float)(DateTime.Now - oldDate).TotalSeconds;
                    int      n           = (int)Mathf.Floor((skipSeconds / modifyResourceTimeout));
                    //设置最大的托管时间间隔(1小时之外的资源无效)
                    int maxN = maxModifyResourceTimeout / modifyResourceTimeout;
                    //记录倒计时时间
                    data[0] = skipSeconds < modifyResourceTimeout ? (int)(modifyResourceTimeout - skipSeconds) : modifyResourceTimeout;
                    if (n > 0)
                    {
                        n = n > maxN ? maxN : n;
                        int    id           = sqReader.GetInt32(sqReader.GetOrdinal("Id"));
                        string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData"));
                        resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr);
                        List <ResourceData> resources       = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourcesStr);
                        List <ResourceData> resultResources = returnAllReceiveResourcesOnece(resources, n);
                        if (resultResources.Count > 0)
                        {
                            ResourceData result;
                            ResourceData find;
                            for (int i = 0; i < resultResources.Count; i++)
                            {
                                result = resultResources[i];
                                find   = resources.Find(item => item.Type == result.Type);
                                if (find != null)
                                {
                                    //累加拥有的资源
                                    find.Num += result.Num;
                                    find.Num  = find.Num < 0 ? 0 : find.Num;
                                }
                            }
                            db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "', Ticks = " + DateTime.Now.Ticks + " where Id = " + id);
                        }
                        else
                        {
                            //没有产出也需要更新时间戳
                            db.ExecuteQuery("update WorkshopResourceTable set Ticks = " + DateTime.Now.Ticks + " where Id = " + id);
                        }
                        //添加收获的资源列表
                        data[1] = JsonManager.GetInstance().SerializeObject(resultResources);
                        //计算单位产出
                        data[2] = JsonManager.GetInstance().SerializeObject(returnAllReceiveResourcesOnece(resources));
                    }
                }
                db.CloseSqlConnection();
            }
            catch (Exception e) {
                db.CloseSqlConnection();
                Debug.LogWarning("ModifyResources-------------------error:" + e.ToString() + " - " + e.StackTrace);
                return;
            }
            Messenger.Broadcast <JArray>(NotifyTypes.ModifyResourcesEcho, data);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// 增减资源的工作家丁数
        /// </summary>
        /// <param name="type">Type.</param>
        /// <param name="addNum">Add number.</param>
        public void ChangeResourceWorkerNum(ResourceType type, int addNum)
        {
            if (addNum == 0)
            {
                return;
            }
            addNum = Mathf.Clamp(addNum, -1, 1);
            JArray data = new JArray();

            try {
                db = OpenDb();
                SqliteDataReader sqReader = db.ExecuteQuery("select * from WorkshopResourceTable where BelongToRoleId = '" + currentRoleId + "'");
                if (sqReader.Read())
                {
//					int workerNum = sqReader.GetInt32(sqReader.GetOrdinal("WorkerNum"));
//                    int maxWorkerNum = sqReader.GetInt32(sqReader.GetOrdinal("MaxWorkerNum"));
                    int workerNum    = GetWorkerNum();
                    int maxWorkerNum = GetMaxWorkerNum();
                    if (addNum > 0 && workerNum == 0)
                    {
                        db.CloseSqlConnection();
                        return;
                    }
                    int    id           = sqReader.GetInt32(sqReader.GetOrdinal("Id"));
                    string resourcesStr = sqReader.GetString(sqReader.GetOrdinal("ResourcesData"));
                    resourcesStr = resourcesStr.IndexOf("[") == 0 ? resourcesStr : DESStatics.StringDecder(resourcesStr);
                    string resourceDataStr           = resourcesStr;
                    List <ResourceData> resources    = JsonManager.GetInstance().DeserializeObject <List <ResourceData> >(resourceDataStr);
                    ResourceData        findResource = resources.Find(item => item.Type == type);
                    if (findResource != null)
                    {
                        if (addNum < 0 && findResource.WorkersNum == 0)
                        {
                            db.CloseSqlConnection();
                            return;
                        }
                        findResource.WorkersNum += addNum;
                        findResource.WorkersNum  = findResource.WorkersNum < 0 ? 0 : findResource.WorkersNum;
                        workerNum -= addNum;
                        workerNum  = workerNum < 0 ? 0 : (workerNum > maxWorkerNum ? maxWorkerNum : workerNum);
                        List <ResourceData> resultResources = returnAllReceiveResourcesOnece(resources);
                        data.Add((short)type);
                        data.Add(findResource.WorkersNum);
                        data.Add(workerNum);
                        data.Add(maxWorkerNum);
                        data.Add(JsonManager.GetInstance().SerializeObject(resultResources));
                        //更新数据
                        db.ExecuteQuery("update WorkshopResourceTable set ResourcesData = '" + DESStatics.StringEncoder(JsonManager.GetInstance().SerializeObject(resources)) + "', WorkerNum = " + workerNum + " where Id = " + id);
                        SetWorkerNum(workerNum);
                    }
                }
                db.CloseSqlConnection();
            }
            catch (Exception e) {
                db.CloseSqlConnection();
                Debug.LogWarning("ChangeResourceWorkerNum-------------------error:" + e.ToString() + " - " + e.StackTrace);
                return;
            }
            if (data.Count > 0)
            {
                Messenger.Broadcast <JArray>(NotifyTypes.ChangeResourceWorkerNumEcho, data);
            }
        }