コード例 #1
0
        /// <summary>
        /// 吃干粮
        /// </summary>
        /// <returns>The food.</returns>
        /// <param name="num">Number.</param>
        public int EatFood(int num)
        {
            int eatNum = 0;

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

            if (sqReader.Read())
            {
                int      userDataId = sqReader.GetInt32(sqReader.GetOrdinal("Id"));
                UserData user       = JsonManager.GetInstance().DeserializeObject <UserData>(sqReader.GetString(sqReader.GetOrdinal("Data")));
                user.AreaFood.Num = sqReader.GetInt32(sqReader.GetOrdinal("AreaFoodNum"));
                user.AreaFood.Num = user.AreaFood.Num > user.AreaFood.MaxNum ? user.AreaFood.MaxNum : user.AreaFood.Num;
                if (user.AreaFood.Num < user.AreaFood.MaxNum)
                {
                    eatNum             = user.AreaFood.MaxNum - user.AreaFood.Num;
                    eatNum             = eatNum <= num ? eatNum : num;
                    user.AreaFood.Num += eatNum;
                    //更新当前干粮
                    db.ExecuteQuery("Update UserDatasTable set Data = '" + JsonManager.GetInstance().SerializeObjectDealVector(user) + "', AreaFoodNum = " + user.AreaFood.Num + " where Id = " + userDataId);
                    AreaMainPanelCtrl.MakeUpdateFoods(user.AreaFood.Num);
                }
            }
            db.CloseSqlConnection();
            return(eatNum);
        }
コード例 #2
0
        /// <summary>
        /// 吃干粮
        /// </summary>
        /// <param name="id">Identifier.</param>
        /// <param name="num">Number.</param>
        public void Eat(int id, int num)
        {
            int eatNum = 0;

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

            if (sqReader.Read())
            {
                int      userDataId = sqReader.GetInt32(sqReader.GetOrdinal("Id"));
                UserData user       = JsonManager.GetInstance().DeserializeObject <UserData>(sqReader.GetString(sqReader.GetOrdinal("Data")));
                user.AreaFood.Num = sqReader.GetInt32(sqReader.GetOrdinal("AreaFoodNum"));
                user.AreaFood.Num = user.AreaFood.Num > user.AreaFood.MaxNum ? user.AreaFood.MaxNum : user.AreaFood.Num;
                if (user.AreaFood.Num < user.AreaFood.MaxNum)
                {
                    eatNum             = user.AreaFood.MaxNum - user.AreaFood.Num;
                    eatNum             = eatNum <= num ? eatNum : num;
                    user.AreaFood.Num += eatNum;
                    num -= eatNum;
                    if (num > 0)
                    {
                        //减掉吃掉的干粮辎重
                        db.ExecuteQuery("update BagTable set Num = " + num + " where Id = " + id);
                    }
                    else
                    {
                        //删除干粮辎重
                        db.ExecuteQuery("delete from BagTable where Id = " + id);
                    }
                    //更新当前干粮
                    db.ExecuteQuery("Update UserDatasTable set Data = '" + JsonManager.GetInstance().SerializeObjectDealVector(user) + "', AreaFoodNum = " + user.AreaFood.Num + " where Id = " + userDataId);
                    AreaMainPanelCtrl.MakeUpdateFoods(user.AreaFood.Num);
                }
                else
                {
                    AlertCtrl.Show("目前体力充沛不需要进食!");
                }
            }
            db.CloseSqlConnection();
            if (eatNum > 0)
            {
                Statics.CreatePopMsg(Vector3.zero, string.Format("补充了{0}个干粮", eatNum), Color.green, 30);
                GetBagPanelData();
            }
        }
コード例 #3
0
        /// <summary>
        /// Scenes the notify init.
        /// </summary>
        public static void RoleNotifyInit()
        {
            Messenger.AddListener <bool>(NotifyTypes.CallRoleInfoPanelData, (isfighting) => {
                DbManager.Instance.CallRoleInfoPanelData(isfighting);
            });

            Messenger.AddListener <JObject, bool>(NotifyTypes.CallRoleInfoPanelDataEcho, (obj, isfighting) => {
//                RoleInfoPanelCtrl.Show((JArray)obj["data"], isfighting);
                RolesInfoPanelCtrl.Show((JArray)obj["data"]);
                if (!isfighting)
                {
                    Messenger.Broadcast(NotifyTypes.ShowTaskBtnPanel);
                }
            });

            Messenger.AddListener(NotifyTypes.HideRoleInfoPanel, () => {
//                RoleInfoPanelCtrl.MoveDown();
                RolesInfoPanelCtrl.MoveDown();
                Messenger.Broadcast(NotifyTypes.HideTaskBtnPanel);
            });

            Messenger.AddListener(NotifyTypes.MakeRoleInfoPanelRedPointRefresh, () => {
                RolesInfoPanelCtrl.MakeRefreshRedPoint();
            });

            Messenger.AddListener(NotifyTypes.MakeReviewRole, () => {
                RolesInfoPanelCtrl.MakeReviewRole();
            });

            Messenger.AddListener <bool>(NotifyTypes.MakeChangeRoleEnable, (enable) => {
                RoleInfoPanelCtrl.MakeChangeRoleEnable(enable);
            });

            Messenger.AddListener <bool>(NotifyTypes.MakeChangeBookEnable, (enable) => {
                RoleInfoPanelCtrl.MakeChangeBookEnable(enable);
            });

            Messenger.AddListener <bool>(NotifyTypes.MakeRoleInfoPanelDisable, (dis) => {
                RoleInfoPanelCtrl.MakeDisable(dis);
            });

            Messenger.AddListener <string>(NotifyTypes.GetRolesOfWinShopPanelData, (cityId) => {
                DbManager.Instance.GetRolesOfWinShopPanelData(cityId);
            });

            Messenger.AddListener <List <RoleData> >(NotifyTypes.GetRolesOfWinShopPanelDataEcho, (roles) => {
                roles.Sort((a, b) => b.Id.CompareTo(a.Id));
                RolesOfWinShopPanelCtrl.Show(roles);
            });

            Messenger.AddListener(NotifyTypes.GetWeaponsListPanelData, () => {
                DbManager.Instance.GetWeaponsListPanelData();
            });

            Messenger.AddListener <List <WeaponData>, RoleData>(NotifyTypes.GetWeaponsListPanelDataEcho, (weapons, host) => {
                WeaponListPanelCtrl.Show(weapons, host);
            });

            Messenger.AddListener <int, string>(NotifyTypes.ReplaceWeapon, (id, beUsingByRoleId) => {
                DbManager.Instance.ReplaceWeapon(id, beUsingByRoleId);
            });

            Messenger.AddListener <int>(NotifyTypes.TakeOffWeapon, (id => {
                DbManager.Instance.TakeOffWeapon(id);
                SoundManager.GetInstance().PushSound("ui0008");
            }));

            Messenger.AddListener(NotifyTypes.GetBooksListPanelData, () => {
                DbManager.Instance.GetBooksListPanelData();
            });

            Messenger.AddListener <List <BookData> >(NotifyTypes.GetBooksListPanelDataEcho, (books) => {
                BookListPanelCtrl.Show(books);
            });

            Messenger.AddListener <int>(NotifyTypes.UseBook, (id => {
                DbManager.Instance.UseBook(id);
            }));

            Messenger.AddListener <int>(NotifyTypes.UnuseBook, (id => {
                DbManager.Instance.UnuseBook(id);
                SoundManager.GetInstance().PushSound("ui0008");
            }));

            Messenger.AddListener <string>(NotifyTypes.GetBooksOfForbiddenAreaPanelData, (cityId) => {
                DbManager.Instance.GetBooksOfForbiddenAreaPanelData(cityId);
            });

            Messenger.AddListener <List <BookData>, RoleData>(NotifyTypes.GetBooksOfForbiddenAreaPanelDataEcho, (books, host) => {
                BooksOfForbiddenAreaPanelCtrl.Show(books, host);
            });

            Messenger.AddListener <int>(NotifyTypes.InviteRole, (id) => {
//                DbManager.Instance.InviteRole(id);
                DbManager.Instance.InviteRoleWithResources(id);
            });

            Messenger.AddListener <int>(NotifyTypes.ReadBook, (id => {
                DbManager.Instance.ReadBook(id);
            }));

            Messenger.AddListener(NotifyTypes.GetReadyToTravelPanelData, () => {
                DbManager.Instance.GetReadyToTravelPanelData();
            });

            Messenger.AddListener <List <RoleData>, UserData>(NotifyTypes.GetReadyToTravelPanelDataEcho, (roles, user) => {
                Messenger.Broadcast(NotifyTypes.HideRoleInfoPanel);
                roles.Sort(sortReadyToTravelRoles);
                ReadyToTravelPanelCtrl.Show(roles, user);
            });

            Messenger.AddListener <RoleData>(NotifyTypes.MakeSelectRoleInTeam, (role) => {
                ReadyToTravelPanelCtrl.MakeSelectRole(role);
            });

            Messenger.AddListener <RoleData>(NotifyTypes.MakeUnSelectRoleInTeam, (role) => {
                ReadyToTravelPanelCtrl.MakeUnSelectRole(role);
            });

            Messenger.AddListener <JArray>(NotifyTypes.ChangeRolesSeatNo, (ids) => {
                DbManager.Instance.ChangeRolesSeatNo(ids);
            });

            Messenger.AddListener(NotifyTypes.EnterAreaFromCity, () => {
                Messenger.Broadcast(NotifyTypes.HideCityScenePanel);
                Messenger.Broadcast(NotifyTypes.FromCitySceneBackToArea);
                Messenger.Broadcast(NotifyTypes.CallAreaMainPanelData);
                ReadyToTravelPanelCtrl.Hide();
            });

            Messenger.AddListener(NotifyTypes.GetHospitalPanelData, () => {
                DbManager.Instance.GetHospitalPanelData();
            });

            Messenger.AddListener <List <RoleData> >(NotifyTypes.GetHospitalPanelDataEcho, (roles) => {
                roles.Sort((a, b) => b.Injury.CompareTo(a.Injury));
                HospitalPanelCtrl.Show(roles);
            });

            Messenger.AddListener <int>(NotifyTypes.CureRole, (id => {
                DbManager.Instance.CureRole(id);
            }));

            Messenger.AddListener(NotifyTypes.RelieveRoles, () => {
                DbManager.Instance.RelieveRoles();
            });

            Messenger.AddListener(NotifyTypes.GetBagPanelData, () => {
                DbManager.Instance.GetBagPanelData();
            });

            Messenger.AddListener <List <ItemData>, double>(NotifyTypes.GetBagPanelDataEcho, (items, silver) => {
                BagPanelCtrl.Show(items, silver);
            });

            Messenger.AddListener <ItemData, bool>(NotifyTypes.ShowItemDetailPanel, (item, fromBag) => {
                ItemDetailPanelCtrl.Show(item, fromBag);
            });

            Messenger.AddListener(NotifyTypes.GetSellItemsPanelData, () => {
                DbManager.Instance.GetSellItemsPanelData();
            });

            Messenger.AddListener <List <ItemData> >(NotifyTypes.GetSellItemsPanelDataEcho, (items) => {
                SellItemsPanelCtrl.Show(items);
            });

            Messenger.AddListener(NotifyTypes.MakeSelectedItemOfSellItemsPanel, () => {
                SellItemsPanelCtrl.MakeSelectedItem();
            });

            Messenger.AddListener <JArray>(NotifyTypes.SellItems, (ids) => {
                DbManager.Instance.SellItems(ids);
            });

            Messenger.AddListener <double>(NotifyTypes.SellItemsEcho, (silver) => {
                SellItemsPanelCtrl.Hide();
                StorePanelCtrl.MakeChangeSilverNum(silver);
                SoundManager.GetInstance().PushSound("ui0005");
            });

            Messenger.AddListener <int>(NotifyTypes.DiscardItem, (id) => {
                DbManager.Instance.DiscardItem(id);
                SoundManager.GetInstance().PushSound("ui0008");
            });

            Messenger.AddListener <BookData>(NotifyTypes.ShowBookDetailPanel, (book) => {
                BookDetailPanelCtrl.Show(book, DbManager.Instance.GetBookExpAndSecrets(book.Id));
            });

            Messenger.AddListener <WeaponData>(NotifyTypes.ShowWeaponDetailPanel, (weapon) => {
                WeaponDetailPanelCtrl.Show(weapon, DbManager.Instance.GetWeaponLV(weapon.Id));
            });

            Messenger.AddListener <WeaponData>(NotifyTypes.WeaponLVUpgrade, (weapon) => {
                DbManager.Instance.WeaponLVUpgrade(weapon);
            });

            Messenger.AddListener <WeaponLVData>(NotifyTypes.WeaponLVUpgradeEcho, (lvData) => {
                WeaponDetailPanelCtrl.WeaponLVUpgrade(lvData);
            });

            Messenger.AddListener <RoleData>(NotifyTypes.ShowRoleDetailPanel, (role) => {
                RoleDetailPanelCtrl.Show(role, DbManager.Instance.GetSecretsBelongBooks(role.ResourceBookDataIds));
            });

            Messenger.AddListener <List <DropData> >(NotifyTypes.ShowDropsListPanel, (drops) => {
                DropsListPanelCtrl.Show(drops);
                SoundManager.GetInstance().PushSound("ui0004");
            });

            Messenger.AddListener <int>(NotifyTypes.UseItem, (id => {
                DbManager.Instance.UseItem(id);
            }));

            Messenger.AddListener <string>(NotifyTypes.GetInnInCityData, (cityId) => {
                DbManager.Instance.GetInnInCityData(cityId);
            });

            Messenger.AddListener <List <FloydResult> >(NotifyTypes.GetInnInCityDataEcho, (results) => {
                InnPanelCtrl.Show(results);
            });

            Messenger.AddListener <int, int>(NotifyTypes.GoToCity, (fromIndex, toIndex) => {
                DbManager.Instance.GoToCity(fromIndex, toIndex);
            });

            Messenger.AddListener <SceneData>(NotifyTypes.GoToCityEcho, (scene) => {
                string eventId = JsonManager.GetInstance().GetMapping <string>("AreaCityPosDatas", scene.Id);
                string[] fen   = eventId.Split(new char[] { '_' });
                if (fen.Length >= 3)
                {
                    string areaName = fen[0];
                    int x           = int.Parse(fen[1]);
                    int y           = int.Parse(fen[2]);
                    if (UserModel.CurrentUserData != null)
                    {
                        CityScenePanelCtrl.MakeClose();
                        InnPanelCtrl.Hide();
                        UserModel.CurrentUserData.PositionStatu        = UserPositionStatusType.InCity;
                        UserModel.CurrentUserData.CurrentCitySceneId   = scene.Id;
                        UserModel.CurrentUserData.CurrentAreaSceneName = areaName;
                        UserModel.CurrentUserData.CurrentAreaX         = x;
                        UserModel.CurrentUserData.CurrentAreaY         = y;
                        //清空临时事件
                        Messenger.Broadcast <List <SceneEventType> >(NotifyTypes.ClearDisableEventIdMapping, new List <SceneEventType>()
                        {
                            SceneEventType.DisablePagoda
                        });
                        Messenger.Broadcast <System.Action <UserData> >(NotifyTypes.UpdateUserData, null);
                        Messenger.Broadcast <string>(NotifyTypes.GoToScene, areaName);
                    }
                }
            });

            Messenger.AddListener <string>(NotifyTypes.NpcsEventHandler, (npcId) => {
                switch (npcId)
                {
                case "05002001":
                    if (DbManager.Instance.HostData.Occupation == OccupationType.None)
                    {
                        if (!DbManager.Instance.HasAnyTask((new List <string>()
                        {
                            "task_occupation0",
                            "task_occupation1",
                            "task_occupation2",
                            "task_occupation3",
                            "task_occupation4",
                            "task_occupation5"
                        }).ToArray()))
                        {
                            OccupationPanelCtrl.Show();
                        }
                        else
                        {
                            AlertCtrl.Show("去吧去吧,老夫已为你做了引荐");
                        }
                    }
                    else
                    {
                        AlertCtrl.Show(string.Format("你已是{0},可喜可贺啊,哦哈哈哈哈", Statics.GetOccupationDesc(DbManager.Instance.HostData.Occupation)));
                    }
                    break;

                default:
                    break;
                }
            });

            Messenger.AddListener <int>(NotifyTypes.HostRoleUpgrade, (toLv) => {
                DbManager.Instance.HostRoleUpgrade(toLv);
            });

            Messenger.AddListener <RoleData, RoleData>(NotifyTypes.HostRoleUpgradeEcho, (roleData, toData) => {
                RoleUpgradeLvPanelCtrl.Show(roleData, toData);
                SoundManager.GetInstance().PushSound("ui0002");
            });

            Messenger.AddListener(NotifyTypes.OpenRepairBugPanel, () => {
                RepairBugPanelCtrl.Show();
            });

            Messenger.AddListener <BookData, List <SecretData> >(NotifyTypes.GetSecretListPanelData, (book, hasSecrets) => {
                SecretListPanelCtrl.Show(DbManager.Instance.GetEffectiveSecrets(), book, hasSecrets);
            });

            Messenger.AddListener <BookData, List <SecretData> >(NotifyTypes.DealSecretEcho, (book, hasSecrets) => {
                if (RolesInfoPanelCtrl.Ctrl != null)
                {
                    Messenger.Broadcast <bool>(NotifyTypes.CallRoleInfoPanelData, false);
                    Messenger.Broadcast(NotifyTypes.MakeReviewRole);
                }
                Messenger.Broadcast <BookData>(NotifyTypes.ShowBookDetailPanel, book);
                Messenger.Broadcast <BookData, List <SecretData> >(NotifyTypes.GetSecretListPanelData, book, hasSecrets);
            });

            Messenger.AddListener(NotifyTypes.OpenTowerGuiderPanel, () => {
                TowerGuiderPanelCtrl.Show();
                AreaMainPanelCtrl.MakeRefreshDifficultyView();
            });
        }
コード例 #4
0
        /// <summary>
        /// Scenes the notify init.
        /// </summary>
        public static void AreaNotifyInit()
        {
            Messenger.AddListener <AreaTarget, AreaMain>(NotifyTypes.AreaInit, (target, main) => {
                AreaModel.CurrentTarget  = target;
                AreaModel.AreaMainScript = main;
                //加载动态事件列表
                Messenger.Broadcast <string>(NotifyTypes.GetActiveEventsInArea, UserModel.CurrentUserData.CurrentAreaSceneName);
                //打开大地图UI交互界面
                Messenger.Broadcast(NotifyTypes.CallAreaMainPanelData);
                //如果当前所处的位置是城镇,则进入城镇
                if (UserModel.CurrentUserData.PositionStatu == UserPositionStatusType.InCity)
                {
                    Messenger.Broadcast <string>(NotifyTypes.EnterCityScene, UserModel.CurrentUserData.CurrentCitySceneId);
                }
            });

            Messenger.AddListener(NotifyTypes.AreaDestroyed, () => {
                if (AreaModel.CurrentTarget != null && AreaModel.CurrentTarget.gameObject != null)
                {
                    MonoBehaviour.Destroy(AreaModel.CurrentTarget.gameObject);
                    AreaModel.CurrentTarget = null;
                }
                Messenger.Broadcast(NotifyTypes.HideAreaMainPanel);
            });

            Messenger.AddListener(NotifyTypes.CallAreaMainPanelData, () => {
                Messenger.Broadcast <System.Action <UserData> >(NotifyTypes.CallUserData, (userData) => {
                    Messenger.Broadcast <JArray>(NotifyTypes.CallAreaMainPanelDataEcho, new JArray(userData.AreaFood.IconId, userData.AreaFood.Num, userData.AreaFood.MaxNum, userData.CurrentAreaSceneName));
                    Vector2 pos = new Vector2(userData.CurrentAreaX, userData.CurrentAreaY);
                    Messenger.Broadcast <Vector2, bool>(NotifyTypes.SetAreaPosition, pos, false);
                });
            });

            Messenger.AddListener <JArray>(NotifyTypes.CallAreaMainPanelDataEcho, (data) => {
                AreaMainPanelCtrl.Show(data);
                Messenger.Broadcast(NotifyTypes.MakeUpdateProps);
            });

            Messenger.AddListener(NotifyTypes.MakeUpdateProps, () => {
                AreaMainPanelCtrl.MakeUpdateProps(DbManager.Instance.GetAllProps());
            });

            Messenger.AddListener <PropType, int>(NotifyTypes.AddProp, (type, num) => {
                DbManager.Instance.AddProp(type, num);
                Messenger.Broadcast(NotifyTypes.MakeUpdateProps);
            });

            Messenger.AddListener <PropType, int>(NotifyTypes.UseProp, (type, num) => {
                DbManager.Instance.UseProp(type, num);
            });

            Messenger.AddListener(NotifyTypes.HideAreaMainPanel, () => {
                AreaMainPanelCtrl.Hide();
            });

            Messenger.AddListener <string, bool>(NotifyTypes.MoveOnArea, (direction, duringMove) => {
                //如果触发战斗则禁止移动
                if (BattleFightPanelCtrl.Ctrl != null || !AreaModel.CurrentTarget.CanTriggerEvent())
                {
                    return;
                }
                //移动前先判断移动目的地是否有战斗
                Vector2 nextMovePosition = AreaModel.CurrentTarget.GetNextMovePosition(direction);
                //判断前方是否是障碍
                tk2dRuntime.TileMap.TileInfo groundTile = AreaModel.CurrentTarget.GetTileInfo((int)nextMovePosition.x, (int)nextMovePosition.y, 0);
                //判断禁止通过的碰撞区域
                if (groundTile == null || groundTile.stringVal == "obstacle")
                {
                    Statics.CreatePopMsg(Vector3.zero, "撞到墙上了,请绕行", Color.white, 30);
                    return;
                }
                string fightEventId = string.Format("{0}_{1}_{2}", UserModel.CurrentUserData.CurrentAreaSceneName, (int)nextMovePosition.x, (int)nextMovePosition.y);
                EventData data;

                if (AreaMain.ActiveAreaEventsMapping.ContainsKey(fightEventId))
                {
                    data = AreaMain.ActiveAreaEventsMapping[fightEventId];
                    if (data.Type == SceneEventType.Battle)
                    {
                        ConfirmCtrl.Show("前方将有恶战,是否继续?", () => {
                            Messenger.Broadcast <string>(NotifyTypes.CreateBattle, data.EventId);
                        }, null, "动手", "撤退");
                        return;
                    }
                }
                else if (AreaMain.StaticAreaEventsMapping.ContainsKey(fightEventId))
                {
                    //判断静态事件是否禁用
                    if (!AreaMain.DisableEventIdMapping.ContainsKey(fightEventId))
                    {
                        data = AreaMain.StaticAreaEventsMapping[fightEventId];
                        if (data.Type == SceneEventType.Battle)
                        {
                            ConfirmCtrl.Show("前方将有恶战,是否继续?", () => {
                                Messenger.Broadcast <string>(NotifyTypes.CreateBattle, data.EventId);
                                //处理静态事件的预禁用操作
                                EventData disableEvent = new EventData();
                                disableEvent.Id        = fightEventId;
                                disableEvent.Type      = SceneEventType.DisableEvent;
                                disableEvent.X         = (int)nextMovePosition.x;
                                disableEvent.Y         = (int)nextMovePosition.y;
                                Messenger.Broadcast <EventData>(NotifyTypes.HandleDisableEvent, disableEvent);
                            }, null, "动手", "撤退");
                            return;
                        }
                        if (data.Type == SceneEventType.Pagoda)
                        {
                            ConfirmCtrl.Show("前方有守卫,是否继续?", () => {
                                string eventId = data.EventId;
                                if (eventId == "10310020")
                                {
                                    //处理金兀术难度选择后战斗id的变化
                                    int difficulty = PlayerPrefs.GetInt("TowerDifficulty");
                                    switch (difficulty)
                                    {
                                    case 1:
                                        eventId = "10310021";
                                        break;

                                    case 2:
                                        eventId = "10310022";
                                        break;

                                    default:
                                        break;
                                    }
                                }
                                Messenger.Broadcast <string>(NotifyTypes.CreateBattle, eventId);
                                //处理静态事件的预禁用操作
                                EventData disableEvent = new EventData();
                                disableEvent.Id        = fightEventId;
                                disableEvent.EventId   = eventId;
                                disableEvent.Type      = SceneEventType.DisablePagoda;
                                disableEvent.X         = (int)nextMovePosition.x;
                                disableEvent.Y         = (int)nextMovePosition.y;
                                Messenger.Broadcast <EventData>(NotifyTypes.HandleDisableEvent, disableEvent);
                            }, null, "动手", "撤退");
                            return;
                        }
                        else if (data.OpenType != SceneEventOpenType.None)
                        {
                            //静态事件有一个开启判定类型
                            switch (data.OpenType)
                            {
                            case SceneEventOpenType.FightWined:
                                if (!DbManager.Instance.IsFightWined(data.OpenKey))
                                {
                                    ConfirmCtrl.Show(string.Format("前方有强敌守卫,是否硬闯?{0}", data.Notice), () => {
                                        Messenger.Broadcast <string>(NotifyTypes.CreateBattle, data.OpenKey);
                                    }, null, "动手", "撤退");
                                    return;
                                }
                                break;

                            case SceneEventOpenType.NeedItem:
                                if (DbManager.Instance.GetUsedItemNumByItemId(data.OpenKey) <= 0)
                                {
                                    ItemData item = JsonManager.GetInstance().GetMapping <ItemData>("ItemDatas", data.OpenKey);
                                    if (DbManager.Instance.GetItemNumByItemId(data.OpenKey) > 0)
                                    {
                                        ConfirmCtrl.Show(string.Format("需要交出 <color=\"#1ABDE6\">{0}</color> 才能通过", item.Name), () => {
                                            if (DbManager.Instance.CostItemFromBag(data.OpenKey, 1))
                                            {
                                                DbManager.Instance.UpdateUsedItemRecords(data.OpenKey, 1);
                                                AlertCtrl.Show(string.Format("交出了 <color=\"#1ABDE6\">{0}</color>", item.Name));
                                            }
                                        }, null, "给", "不给");
                                    }
                                    else
                                    {
                                        AlertCtrl.Show(string.Format("行囊里没有<color=\"#1ABDE6\">{0}</color>,不能过去!{1}", item.Name, data.Notice));
                                    }
                                    return;
                                }
                                break;

                            case SceneEventOpenType.NeedTasks:
                                if (!string.IsNullOrEmpty(data.StringValue))
                                {
                                    string[] taskIds = data.StringValue.Split(new char[] { '|' });
                                    if (!DbManager.Instance.HasAnyTask(taskIds))
                                    {
                                        AlertCtrl.Show(string.Format("前方暂时无法通过!\n<color=\"#00FF00\">{0}</color>", data.Notice));
                                        return;
                                    }
                                }
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
                //判定体力是否足够移动
                DbManager.Instance.MoveOnArea(direction, duringMove);
//				Messenger.Broadcast<string, int, bool>(NotifyTypes.MoveOnAreaEcho, direction, 666, duringMove);
            });

            Messenger.AddListener <string, int, bool>(NotifyTypes.MoveOnAreaEcho, (direction, foodsNum, duringMove) => {
                if (foodsNum > 0)
                {
                    AreaMainPanelCtrl.MakeArrowShow(direction, foodsNum);
                    Vector2 pos = AreaModel.CurrentTarget.Move(direction, foodsNum > 0, duringMove);
                    AreaMainPanelCtrl.MakeSetPosition(pos);
                }
                else
                {
                    if (UserModel.CurrentRebornTimes >= UserModel.MaxRebornTimes)
                    {
                        AlertCtrl.Show("干粮耗尽, 先回城镇休整", () => {
                            Messenger.Broadcast(NotifyTypes.BackToCity);
                        });
                    }
                    else
                    {
//                        ConfirmCtrl.Show(string.Format("干粮耗尽,您愿意观看一段视频获得{0}点体力吗?\n(复活次数:{1}/{2})", UserModel.CurrentFoodNums / 2, UserModel.MaxRebornTimes - UserModel.CurrentRebornTimes, UserModel.MaxRebornTimes), () => {
//                            MaiHandler.StartRewardedVideo(() => {
//                                UserModel.CurrentFoodNums = UserModel.CurrentFoodNums / 2;
//                                UserModel.CurrentRebornTimes++;
//                                Messenger.Broadcast<int>(NotifyTypes.EatFood, UserModel.CurrentFoodNums);
//                            });
//                            MaiHandler.SendEvent("StartRewardedVideoForFoods", DbManager.Instance.HostData.Lv.ToString());
//                        }, () => {
//                            Messenger.Broadcast(NotifyTypes.BackToCity);
//                        }, "观看", "不了");

                        ConfirmCtrl.Show(string.Format("干粮耗尽,您愿意花费5000两银子获得{0}点体力吗?\n(复活次数:{1}/{2})", UserModel.CurrentFoodNums / 2, UserModel.MaxRebornTimes - UserModel.CurrentRebornTimes, UserModel.MaxRebornTimes), () => {
                            if (DbManager.Instance.CostSilver(5000))
                            {
                                UserModel.CurrentFoodNums = UserModel.CurrentFoodNums / 2;
                                UserModel.CurrentRebornTimes++;
                                Messenger.Broadcast <int>(NotifyTypes.EatFood, UserModel.CurrentFoodNums);
                            }
                            else
                            {
                                AlertCtrl.Show("银两不足, 先回城镇休整", () => {
                                    Messenger.Broadcast(NotifyTypes.BackToCity);
                                });
                            }
                            MaiHandler.SendEvent("StartRewardedVideoForFoods", DbManager.Instance.HostData.Lv.ToString());
                        }, () => {
                            Messenger.Broadcast(NotifyTypes.BackToCity);
                        }, "花钱", "不了");
                    }
                    BattleFightPanelCtrl.Hide(); //强制退出战斗
                }
            });

            Messenger.AddListener <Vector2, bool>(NotifyTypes.SetAreaPosition, (pos, doEvent) => {
                AreaMainPanelCtrl.MakeSetPosition(pos);
                if (AreaModel.AreaMainScript != null)
                {
                    AreaModel.AreaMainScript.SetPosition(pos, doEvent);
                }
            });

            Messenger.AddListener <string>(NotifyTypes.GetActiveEventsInArea, (sceneId) => {
                DbManager.Instance.GetActiveEventsInArea(sceneId);
            });

            Messenger.AddListener <List <EventData> >(NotifyTypes.GetActiveEventsInAreaEcho, (events) => {
                if (AreaModel.AreaMainScript != null)
                {
                    AreaModel.AreaMainScript.UpdateActiveAreaEventsData(events);
                    AreaModel.AreaMainScript.RefreshActiveAreaEventsView();
                }
            });

            Messenger.AddListener <EventData>(NotifyTypes.HandleDisableEvent, (ev) => {
                if (AreaModel.AreaMainScript != null)
                {
                    AreaModel.AreaMainScript.HandleDisableEvent(ev);
                }
            });

            Messenger.AddListener <bool>(NotifyTypes.ReleaseDisableEvent, (win) => {
                if (AreaModel.AreaMainScript != null)
                {
                    AreaModel.AreaMainScript.ReleaseDisableEvent(win);
                }
            });

            Messenger.AddListener <string, EventData>(NotifyTypes.PushDisableEvent, (eventId, eventData) => {
                if (AreaModel.AreaMainScript != null)
                {
                    AreaModel.AreaMainScript.PushDisableEvent(eventId, eventData);
                }
            });

            Messenger.AddListener <List <SceneEventType> >(NotifyTypes.ClearDisableEventIdMapping, (excepts) => {
                if (AreaModel.AreaMainScript != null)
                {
                    AreaModel.AreaMainScript.ClearDisableEventIdMapping(excepts);
                }
            });

            Messenger.AddListener <int>(NotifyTypes.EatFood, (num) => {
                int eatNum = DbManager.Instance.EatFood(num);
                AlertCtrl.Show(string.Format("打开包袱发现<color=\"#00FF00\">{0}个干粮</color>{1}", num, eatNum != num ? "\n你的行囊只装得下<color=\"#FF0000\">" + eatNum + "个</color>" : ""));
            });
        }
コード例 #5
0
ファイル: AreaNotify.cs プロジェクト: mengtest/MyWuXia
        /// <summary>
        /// Scenes the notify init.
        /// </summary>
        public static void AreaNotifyInit()
        {
            Messenger.AddListener <AreaTarget, AreaMain>(NotifyTypes.AreaInit, (target, main) => {
                AreaModel.CurrentTarget  = target;
                AreaModel.AreaMainScript = main;
                //加载动态事件列表
                Messenger.Broadcast <string>(NotifyTypes.GetActiveEventsInArea, UserModel.CurrentUserData.CurrentAreaSceneName);
                //打开大地图UI交互界面
                Messenger.Broadcast(NotifyTypes.CallAreaMainPanelData);
                //如果当前所处的位置是城镇,则进入城镇
                if (UserModel.CurrentUserData.PositionStatu == UserPositionStatusType.InCity)
                {
                    Messenger.Broadcast <string>(NotifyTypes.EnterCityScene, UserModel.CurrentUserData.CurrentCitySceneId);
                }
            });

            Messenger.AddListener(NotifyTypes.AreaDestroyed, () => {
                if (AreaModel.CurrentTarget != null && AreaModel.CurrentTarget.gameObject != null)
                {
                    MonoBehaviour.Destroy(AreaModel.CurrentTarget.gameObject);
                    AreaModel.CurrentTarget = null;
                }
                Messenger.Broadcast(NotifyTypes.HideAreaMainPanel);
            });

            Messenger.AddListener(NotifyTypes.CallAreaMainPanelData, () => {
                Messenger.Broadcast <System.Action <UserData> >(NotifyTypes.CallUserData, (userData) => {
                    Messenger.Broadcast <JArray>(NotifyTypes.CallAreaMainPanelDataEcho, new JArray(userData.AreaFood.IconId, userData.AreaFood.Num, userData.AreaFood.MaxNum, userData.CurrentAreaSceneName));
                    Vector2 pos = new Vector2(userData.CurrentAreaX, userData.CurrentAreaY);
                    Messenger.Broadcast <Vector2, bool>(NotifyTypes.SetAreaPosition, pos, false);
                });
            });

            Messenger.AddListener <JArray>(NotifyTypes.CallAreaMainPanelDataEcho, (data) => {
                AreaMainPanelCtrl.Show(data);
            });

            Messenger.AddListener(NotifyTypes.HideAreaMainPanel, () => {
                AreaMainPanelCtrl.Hide();
            });

            Messenger.AddListener <string, bool>(NotifyTypes.MoveOnArea, (direction, duringMove) => {
                //移动前先判断移动目的地是否有战斗
                Vector2 nextMovePosition = AreaModel.CurrentTarget.GetNextMovePosition(direction);
                //判断前方是否是障碍
                tk2dRuntime.TileMap.TileInfo groundTile = AreaModel.CurrentTarget.GetTileInfo((int)nextMovePosition.x, (int)nextMovePosition.y, 0);
                //判断禁止通过的碰撞区域
                if (groundTile == null || groundTile.stringVal == "obstacle")
                {
                    return;
                }
                string fightEventId = string.Format("{0}_{1}_{2}", UserModel.CurrentUserData.CurrentAreaSceneName, (int)nextMovePosition.x, (int)nextMovePosition.y);
                EventData data;

                if (AreaMain.ActiveAreaEventsMapping.ContainsKey(fightEventId))
                {
                    data = AreaMain.ActiveAreaEventsMapping[fightEventId];
                    if (data.Type == SceneEventType.Battle)
                    {
                        ConfirmCtrl.Show("前方将有恶战,是否继续?", () => {
                            Messenger.Broadcast <string>(NotifyTypes.CreateBattle, data.EventId);
                        }, null, "动手", "撤退");
                        return;
                    }
                }
                else if (AreaMain.StaticAreaEventsMapping.ContainsKey(fightEventId))
                {
                    //判断静态事件是否禁用
                    if (!AreaMain.DisableEventIdMapping.ContainsKey(fightEventId))
                    {
                        data = AreaMain.StaticAreaEventsMapping[fightEventId];
                        if (data.Type == SceneEventType.Battle)
                        {
                            ConfirmCtrl.Show("前方将有恶战,是否继续?", () => {
                                Messenger.Broadcast <string>(NotifyTypes.CreateBattle, data.EventId);
                                //处理静态事件的预禁用操作
                                EventData disableEvent = new EventData();
                                disableEvent.Id        = fightEventId;
                                disableEvent.Type      = SceneEventType.DisableEvent;
                                disableEvent.X         = (int)nextMovePosition.x;
                                disableEvent.Y         = (int)nextMovePosition.y;
                                Messenger.Broadcast <EventData>(NotifyTypes.HandleDisableEvent, disableEvent);
                            }, null, "动手", "撤退");
                            return;
                        }
                        else if (data.OpenType != SceneEventOpenType.None)
                        {
                            //静态事件有一个开启判定类型
                            switch (data.OpenType)
                            {
                            case SceneEventOpenType.FightWined:
                                if (!DbManager.Instance.IsFightWined(data.OpenKey))
                                {
                                    ConfirmCtrl.Show(string.Format("前方有强敌守卫,是否硬闯?{0}", data.Notice), () => {
                                        Messenger.Broadcast <string>(NotifyTypes.CreateBattle, data.OpenKey);
                                    }, null, "动手", "撤退");
                                    return;
                                }
                                break;

                            case SceneEventOpenType.NeedItem:
                                if (DbManager.Instance.GetUsedItemNumByItemId(data.OpenKey) <= 0)
                                {
                                    ItemData item = JsonManager.GetInstance().GetMapping <ItemData>("ItemDatas", data.OpenKey);
                                    if (DbManager.Instance.GetItemNumByItemId(data.OpenKey) > 0)
                                    {
                                        ConfirmCtrl.Show(string.Format("需要交出<color=\"#1ABDE6\">{0}</color>才能通过", item.Name), () => {
                                            if (DbManager.Instance.CostItemFromBag(data.OpenKey, 1))
                                            {
                                                DbManager.Instance.UpdateUsedItemRecords(data.OpenKey, 1);
                                            }
                                        }, null, "给", "不给");
                                    }
                                    else
                                    {
                                        AlertCtrl.Show(string.Format("行囊里没有<color=\"#1ABDE6\">{0}</color>,不能过去!{1}", item.Name, data.Notice));
                                    }
                                    return;
                                }
                                break;

                            case SceneEventOpenType.NeedTasks:
                                if (!string.IsNullOrEmpty(data.StringValue))
                                {
                                    string[] taskIds = data.StringValue.Split(new char[] { '|' });
                                    if (!DbManager.Instance.HasAnyTask(taskIds))
                                    {
                                        AlertCtrl.Show(string.Format("前方暂时无法通过!\n<color=\"#00FF00\">{0}</color>", data.Notice));
                                        return;
                                    }
                                }
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
                //判定体力是否足够移动
                DbManager.Instance.MoveOnArea(direction, duringMove);
//				Messenger.Broadcast<string, int, bool>(NotifyTypes.MoveOnAreaEcho, direction, 666, duringMove);
            });

            Messenger.AddListener <string, int, bool>(NotifyTypes.MoveOnAreaEcho, (direction, foodsNum, duringMove) => {
                AreaMainPanelCtrl.MakeArrowShow(direction, foodsNum);
                Vector2 pos = AreaModel.CurrentTarget.Move(direction, foodsNum > 0, duringMove);
                AreaMainPanelCtrl.MakeSetPosition(pos);
                if (foodsNum <= 0)
                {
                    AlertCtrl.Show("干粮耗尽, 先回城镇休整", () => {
                        Messenger.Broadcast(NotifyTypes.BackToCity);
                    });
                }
            });

            Messenger.AddListener <Vector2, bool>(NotifyTypes.SetAreaPosition, (pos, doEvent) => {
                AreaMainPanelCtrl.MakeSetPosition(pos);
                if (AreaModel.AreaMainScript != null)
                {
                    AreaModel.AreaMainScript.SetPosition(pos, doEvent);
                }
            });

            Messenger.AddListener <string>(NotifyTypes.GetActiveEventsInArea, (sceneId) => {
                DbManager.Instance.GetActiveEventsInArea(sceneId);
            });

            Messenger.AddListener <List <EventData> >(NotifyTypes.GetActiveEventsInAreaEcho, (events) => {
                if (AreaModel.AreaMainScript != null)
                {
                    AreaModel.AreaMainScript.UpdateActiveAreaEventsData(events);
                    AreaModel.AreaMainScript.RefreshActiveAreaEventsView();
                }
            });

            Messenger.AddListener <EventData>(NotifyTypes.HandleDisableEvent, (ev) => {
                if (AreaModel.AreaMainScript != null)
                {
                    AreaModel.AreaMainScript.HandleDisableEvent(ev);
                }
            });

            Messenger.AddListener <bool>(NotifyTypes.ReleaseDisableEvent, (win) => {
                if (AreaModel.AreaMainScript != null)
                {
                    AreaModel.AreaMainScript.ReleaseDisableEvent(win);
                }
            });

            Messenger.AddListener <string, EventData>(NotifyTypes.PushDisableEvent, (eventId, eventData) => {
                if (AreaModel.AreaMainScript != null)
                {
                    AreaModel.AreaMainScript.PushDisableEvent(eventId, eventData);
                }
            });

            Messenger.AddListener(NotifyTypes.ClearDisableEventIdMapping, () => {
                if (AreaModel.AreaMainScript != null)
                {
                    AreaModel.AreaMainScript.ClearDisableEventIdMapping();
                }
            });

            Messenger.AddListener <int>(NotifyTypes.EatFood, (num) => {
                int eatNum = DbManager.Instance.EatFood(num);
                AlertCtrl.Show(string.Format("打开包袱发现<color=\"#00FF00\">{0}个干粮</color>{1}", num, eatNum != num ? "\n你的行囊只装得下<color=\"#FF0000\">" + eatNum + "个</color>" : ""));
            });
        }