コード例 #1
0
        public static int GetClipType(Contexts contexts, int weaponKey, FreeData fd)
        {
            var weaponAgent            = fd.Player.WeaponController().GetWeaponAgent(FreeWeaponUtil.GetSlotType(weaponKey));
            WeaponResConfigItem weapon = SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(weaponAgent.ConfigId);

            return(weapon.Caliber);
        }
コード例 #2
0
        private static string putOnPart(FreeData fd, int weaponType, FreeItemInfo info, string toInv = "", ServerRoom room = null)
        {
            WeaponResConfigItem weapon = GetWeapon(fd, weaponType);

            if (weapon != null)
            {
                foreach (EWeaponPartType part in SingletonManager.Get <WeaponPartsConfigManager>().GetAvaliablePartTypes(weapon.Id))
                {
                    int p        = FreeWeaponUtil.GetWeaponPart(part);
                    int detailId = WeaponUtil.GetRealAttachmentId(info.id, weapon.Id);
                    if (SingletonManager.Get <WeaponPartsConfigManager>().IsPartMatchWeapon(detailId, weapon.Id))
                    {
                        if ("p" + p == info.subType)
                        {
                            string        inv = "w" + weaponType + p;
                            ItemInventory ii  = fd.freeInventory.GetInventoryManager().GetInventory(inv);
                            if (ii != null && (ii.posList.Count == 0 ||
                                               toInv.StartsWith("w" + weaponType)))
                            {
                                if (ii.posList.Count > 0)
                                {
                                    DropPart(inv, fd, room);
                                }
                                return(inv);
                            }
                        }
                    }
                }
            }

            return(null);
        }
コード例 #3
0
        private static string putOnPart(FreeData fd, int weaponType, FreeItemInfo info, string toInv = "", ServerRoom room = null)
        {
            WeaponResConfigItem weapon = GetWeapon(fd, weaponType);

            if (weapon != null)
            {
                int detailId         = WeaponPartUtil.GetWeaponFstMatchedPartId(info.id, weapon.Id);
                var weaponconfigMngr = SingletonManager.Get <WeaponConfigManagement>().FindConfigById(weapon.Id);
                foreach (EWeaponPartType part in weaponconfigMngr.ApplyPartsSlot)
                {
                    int p = FreeWeaponUtil.GetWeaponPart(part);
                    if (weaponconfigMngr.IsPartMatchWeapon(detailId))
                    {
                        if ("p" + p == info.subType)
                        {
                            string        inv = "w" + weaponType + p;
                            ItemInventory ii  = fd.freeInventory.GetInventoryManager().GetInventory(inv);
                            if (ii != null && (ii.posList.Count == 0 ||
                                               toInv.StartsWith("w" + weaponType)))
                            {
                                if (ii.posList.Count > 0)
                                {
                                    DropPart(inv, fd, room);
                                }
                                return(inv);
                            }
                        }
                    }
                }
            }

            return(null);
        }
コード例 #4
0
ファイル: PlayerFields.cs プロジェクト: yangfan111/CsharpCode
        public IPara Get(string field)
        {
            if ("id" == field)
            {
                return(new IntPara(field, player.entityKey.Value.EntityId));
            }
            else if ("x" == field)
            {
                return(new FloatPara(field, player.position.Value.x));
            }
            else if ("y" == field)
            {
                return(new FloatPara(field, player.position.Value.y));
            }
            else if ("z" == field)
            {
                return(new FloatPara(field, player.position.Value.z));
            }
            else if ("pitch" == field)
            {
                return(new FloatPara(field, player.orientation.Pitch));
            }
            else if ("yaw" == field)
            {
                return(new FloatPara(field, player.orientation.Yaw));
            }
            else if ("currentWeaponKey" == field)
            {
                return(new IntPara(field, FreeWeaponUtil.GetWeaponKey(player.WeaponController().HeldSlotType)));
            }
            else if ("currentWeaponId" == field)
            {
                return(new IntPara(field, player.WeaponController().HeldWeaponAgent.ConfigId));
            }
            else if ("inCar" == field)
            {
                return(new BoolPara(field, player.IsOnVehicle()));
            }
            else if ("team" == field)
            {
                return(new IntPara(field, (int)player.playerInfo.Camp));
            }
            else if ("isDead" == field)
            {
                return(new BoolPara(field, player.gamePlay.LifeState == (int)EPlayerLifeState.Dead));
            }
            else if ("StrAvatarIds" == field)
            {
                string[] ids = new string[player.playerInfo.AvatarIds.Count];
                for (int i = 0; i < ids.Length; i++)
                {
                    ids[i] = player.playerInfo.AvatarIds[i].ToString();
                }
                return(new StringPara(field, string.Join(",", ids)));
            }

            return(null);
        }
コード例 #5
0
        public override void DoAction(IEventArgs args)
        {
            if (string.IsNullOrEmpty(player))
            {
                player = "current";
            }

            FreeRuleEventArgs fr = (FreeRuleEventArgs)args;

            PlayerEntity playerEntity = (PlayerEntity)fr.GetEntity(player);

            IParable item = args.GetUnit("item");

            if (playerEntity != null && item != null)
            {
                EWeaponSlotType type = FreeWeaponUtil.GetSlotType(FreeUtil.ReplaceInt(weaponKey, args));

                SimpleProto message = FreePool.Allocate();
                message.Key = FreeMessageConstant.ChangeAvatar;

                int itemId = FreeUtil.ReplaceInt("{item.itemId}", args);

                if (!delete)
                {
                    playerEntity.WeaponController().SetWeaponPart(type, itemId);

                    message.Ins.Add((int)type);
                    message.Ins.Add(itemId);
                    message.Ks.Add(3);

                    FreeMessageSender.SendMessage(playerEntity, message);
                    //playerEntity.network.NetworkChannel.SendReliable((int)EServer2ClientMessage.FreeData, message);
                }
                else
                {
                    var part = SingletonManager.Get <WeaponPartsConfigManager>().GetPartType(SingletonManager.Get <WeaponPartSurvivalConfigManager>().GetDefaultPartBySetId(itemId));

                    playerEntity.WeaponController().DeleteWeaponPart(type, part);

                    message.Ins.Add((int)type);
                    message.Ins.Add((int)part);
                    message.Ks.Add(4);

                    FreeMessageSender.SendMessage(playerEntity, message);
                    //playerEntity.network.NetworkChannel.SendReliable((int)EServer2ClientMessage.FreeData, message);
                }
            }
        }
コード例 #6
0
        public override TestValue GetCaseValue(IEventArgs args)
        {
            TestValue tv = new TestValue();

            FreeData fd = (FreeData)args.GetUnit(UnitTestConstant.Tester);

            if (fd != null)
            {
                EWeaponSlotType currentSlot = fd.Player.GetBagLogicImp().GetCurrentWeaponSlot();

                if (args.GetInt(slot) > 0)
                {
                    currentSlot = FreeWeaponUtil.GetSlotType(args.GetInt(slot));
                }

                WeaponInfo info = fd.Player.GetBagLogicImp().GetWeaponInfo(currentSlot);
                tv.AddField("id", info.Id);
                tv.AddField("clip", info.Bullet);
                tv.AddField("carryClip", info.ReservedBullet);
            }

            return(tv);
        }
コード例 #7
0
        public override TestValue GetCaseValue(IEventArgs args)
        {
            TestValue tv = new TestValue();

            FreeData fd = (FreeData)args.GetUnit(UnitTestConstant.Tester);

            if (fd != null)
            {
                EWeaponSlotType currentSlot = fd.Player.WeaponController().HeldSlotType;

                if (args.GetInt(slot) > 0)
                {
                    currentSlot = FreeWeaponUtil.GetSlotType(args.GetInt(slot));
                }

                WeaponScanStruct info = fd.Player.WeaponController().HeldWeaponAgent.ComponentScan;
                tv.AddField("id", info.ConfigId);
                tv.AddField("clip", info.Bullet);
                tv.AddField("carryClip", info.ReservedBullet);
            }

            return(tv);
        }
コード例 #8
0
        public static void AddItemToPlayer(ServerRoom room, PlayerEntity player, int entityId, int cat, int id, int count, string toInv = "")
        {
            SceneObjectEntity entity         = room.RoomContexts.sceneObject.GetEntityWithEntityKey(new Core.EntityComponent.EntityKey(entityId, (short)EEntityType.SceneObject));
            FreeMoveEntity    freeMoveEntity = null;

            if (entity == null || entity.isFlagDestroy)
            {
                freeMoveEntity = room.RoomContexts.freeMove.GetEntityWithEntityKey(new Core.EntityComponent.EntityKey(entityId, (short)EEntityType.FreeMove));
                if (freeMoveEntity == null)
                {
                    return;
                }
            }

            room.FreeArgs.TempUse("current", (FreeData)player.freeData.FreeData);

            if (!FreeItemConfig.Contains(cat, id))
            {
                return;
            }

            FreeItemInfo             item   = FreeItemConfig.GetItemInfo(cat, id);
            CreateItemToPlayerAction action = new CreateItemToPlayerAction();

            FreeData fd = (FreeData)player.freeData.FreeData;

            action.name = "default";

            switch (item.cat)
            {
            case (int)ECategory.Weapon:
                if (item.subType == "w1")
                {
                    action.name = "w1";

                    int c1 = fd.freeInventory.GetInventoryManager().GetInventory("w1").posList.Count;
                    int c2 = fd.freeInventory.GetInventoryManager().GetInventory("w2").posList.Count;


                    if (toInv.StartsWith("w1"))
                    {
                        action.name = "w1";
                        if (c1 > 0)
                        {
                            DropItem(action.name, fd, room);
                        }
                    }
                    else if (toInv.StartsWith("w2"))
                    {
                        action.name = "w2";
                        if (c2 > 0)
                        {
                            DropItem(action.name, fd, room);
                        }
                    }
                    else
                    {
                        if (c1 > 0 && c2 == 0)
                        {
                            action.name = "w2";
                        }

                        if (c1 > 0 && c2 > 0)
                        {
                            int currentKey = FreeWeaponUtil.GetWeaponKey(fd.Player.WeaponController().HeldSlotType);
                            if (currentKey == 0)
                            {
                                currentKey = 1;
                            }
                            if (currentKey == 1 || currentKey == 2)
                            {
                                action.name = "w" + currentKey;
                            }
                            else
                            {
                                action.name = "w1";
                            }

                            DropItem(action.name, fd, room);
                        }
                    }
                }
                else if (item.subType == "w2")
                {
                    action.name = "w3";
                    DropItem(action.name, fd, room);
                }
                else if (item.subType == "w3")
                {
                    action.name = "w4";
                    DropItem(action.name, fd, room);
                }
                else if (item.subType == "w4")
                {
                    action.name = "default";
                }

                break;

            case (int)ECategory.Avatar:
                action.name = item.subType;
                DropItem(item.subType, fd, room);
                break;

            case (int)ECategory.WeaponPart:
                action.name = AutoPutPart(fd, item, toInv, room);
                break;

            default:
                break;
            }

            //handleDropOne(new string[] { "w2" }, action, item, fd, room, entity);
            //handleAddToDefault(new string[] { "p1", "p2", "p3", "p4", "p5" }, action, item, fd, room, entity);

            action.key = FreeItemConfig.GetItemKey(item.cat, item.id);

            bool canAdd = true;

            if (action.name == "default")
            {
                canAdd = BagCapacityUtil.CanAddToBag(room.FreeArgs, fd, item.cat, item.id, count);
            }

            if (canAdd)
            {
                PlayerAnimationAction.DoAnimation(room.RoomContexts, PlayerAnimationAction.Interrupt, fd.Player, true);
                PlayerAnimationAction.DoAnimation(room.RoomContexts, 101, fd.Player, true);

                if (!string.IsNullOrEmpty(action.key))
                {
                    action.count = count.ToString();
                    action.SetPlayer("current");
                    room.FreeArgs.TempUse("current", fd);

                    action.Act(room.FreeArgs);

                    room.FreeArgs.Resume("current");
                }
                else
                {
                    Debug.LogError(item.cat + "-" + item.key + " not existed");
                }

                if (entity != null)
                {
                    entity.isFlagDestroy = true;
                }

                if (freeMoveEntity != null)
                {
                    freeMoveEntity.isFlagDestroy = true;
                }
                //Debug.LogErrorFormat("destroy entity {0}", entity != null);

                FreeSoundUtil.PlayOnce("pick", 225, room.FreeArgs, fd);
            }

            room.FreeArgs.Resume("current");
        }
コード例 #9
0
        private void redrawPart(ItemInventory inventory, ISkillArgs args, ItemPosition ip, FreeData fd)
        {
            if (inventory.name == "w1" || inventory.name == "w2" || inventory.name == "w3")
            {
                int id = (int)((IntPara)ip.GetParameters().Get("itemId")).GetValue();

                WeaponResConfigItem config = SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(id);
                if (config != null)
                {
                    HashSet <int> list = new HashSet <int>();

                    foreach (XmlConfig.EWeaponPartType part in SingletonManager.Get <WeaponPartsConfigManager>().GetAvaliablePartTypes(id))
                    {
                        list.Add(FreeWeaponUtil.GetWeaponPart(part));
                    }

                    List <string> showP = new List <string>();
                    List <string> hideP = new List <string>();

                    for (int i = 1; i <= 5; i++)
                    {
                        if (list.Contains(i))
                        {
                            showP.Add(i.ToString());
                        }
                        else
                        {
                            hideP.Add(i.ToString());
                        }
                    }

                    ShowPartAction show = new ShowPartAction();
                    show.show = true;
                    show.SetPlayer("current");
                    show.SetScope(1);
                    if (inventory.name == "w1")
                    {
                        show.weaponKey = "1";
                    }
                    else if (inventory.name == "w2")
                    {
                        show.weaponKey = "2";
                    }
                    else
                    {
                        show.weaponKey = "3";
                    }

                    show.parts = StringUtil.GetStringFromStrings(showP, ",");
                    show.Act(args);

                    show.show  = false;
                    show.parts = StringUtil.GetStringFromStrings(hideP, ",");
                    show.Act(args);
                }
                else
                {
                    Debug.LogError(ip.key.GetName() + " 没有定义配件.");
                }
            }
        }
コード例 #10
0
        public static bool AddItemToPlayer(ServerRoom room, PlayerEntity player, int entityId, int cat, int id, int count, string toInv = "")
        {
            SceneObjectEntity entity         = room.RoomContexts.sceneObject.GetEntityWithEntityKey(new EntityKey(entityId, (short)EEntityType.SceneObject));
            FreeMoveEntity    freeMoveEntity = null;

            if (entity == null || entity.isFlagDestroy)
            {
                freeMoveEntity = room.RoomContexts.freeMove.GetEntityWithEntityKey(new EntityKey(entityId, (short)EEntityType.FreeMove));
                if (freeMoveEntity == null)
                {
                    return(false);
                }
            }

            FreeData fd = (FreeData)player.freeData.FreeData;

            room.ContextsWrapper.FreeArgs.TempUse("current", fd);

            if (!FreeItemConfig.Contains(cat, id))
            {
                return(false);
            }

            FreeItemInfo             item   = FreeItemConfig.GetItemInfo(cat, id);
            CreateItemToPlayerAction action = new CreateItemToPlayerAction();

            action.name = ChickenConstant.BagDefault;
            switch (item.cat)
            {
            case (int)ECategory.Weapon:
                if (item.subType == ChickenConstant.ItemCatPrimeWeapon)
                {
                    action.name = ChickenConstant.BagPrimeWeapon;

                    int c1 = fd.freeInventory.GetInventoryManager().GetInventory(ChickenConstant.BagPrimeWeapon).posList.Count;
                    int c2 = fd.freeInventory.GetInventoryManager().GetInventory(ChickenConstant.BagSecondaryWeapon).posList.Count;

                    if (toInv.StartsWith(ChickenConstant.BagPrimeWeapon))
                    {
                        action.name = ChickenConstant.BagPrimeWeapon;
                        if (c1 > 0)
                        {
                            DropItem(action.name, fd, room);
                        }
                    }
                    else if (toInv.StartsWith(ChickenConstant.BagSecondaryWeapon))
                    {
                        action.name = ChickenConstant.BagSecondaryWeapon;
                        if (c2 > 0)
                        {
                            DropItem(action.name, fd, room);
                        }
                    }
                    else
                    {
                        if (c1 > 0 && c2 == 0)
                        {
                            action.name = ChickenConstant.BagSecondaryWeapon;
                        }

                        if (c1 > 0 && c2 > 0)
                        {
                            int currentKey = FreeWeaponUtil.GetWeaponKey(fd.Player.WeaponController().HeldSlotType);
                            if (currentKey == 0)
                            {
                                currentKey = 1;
                            }
                            if (currentKey == 1 || currentKey == 2)
                            {
                                action.name = "w" + currentKey;
                            }
                            else
                            {
                                action.name = ChickenConstant.BagPrimeWeapon;
                            }

                            DropItem(action.name, fd, room);
                        }
                    }
                }
                else if (item.subType == ChickenConstant.ItemCatPistolWeapon)
                {
                    action.name = ChickenConstant.BagPistolWeapon;
                    DropItem(action.name, fd, room);
                }
                else if (item.subType == ChickenConstant.ItemCatMeleeWeapon)
                {
                    action.name = ChickenConstant.BagMeleeWeapon;
                    DropItem(action.name, fd, room);
                }
                else if (item.subType == ChickenConstant.ItemCatGrenadeWeapon)
                {
                    action.name = ChickenConstant.BagDefault;
                }
                else if (item.subType == ChickenConstant.ItemCatArmor)
                {
                    action.name = ChickenConstant.BagArmor;
                    if (entity != null)
                    {
                        count = entity.armorDurability.CurDurability;
                    }
                    DropItem(action.name, fd, room);
                }
                else if (item.subType == ChickenConstant.ItemCatHelmet)
                {
                    action.name = ChickenConstant.BagHelmet;
                    if (entity != null)
                    {
                        count = entity.armorDurability.CurDurability;
                    }
                    DropItem(action.name, fd, room);
                }
                break;

            case (int)ECategory.Avatar:
                action.name = item.subType;
                DropItem(item.subType, fd, room);
                break;

            case (int)ECategory.WeaponPart:
                action.name = AutoPutPart(fd, item, toInv, room);
                break;

            default:
                break;
            }
            action.key = FreeItemConfig.GetItemKey(item.cat, item.id);

            int canCount = 0;

            if (action.name == ChickenConstant.BagDefault)
            {
                canCount = BagCapacityUtil.CanAddToBagCount(room.ContextsWrapper.FreeArgs, fd, item.cat, item.id, count);
            }
            else if (item.type == ChickenConstant.ItemCatAvatar || action.name == ChickenConstant.BagHelmet || action.name == ChickenConstant.BagArmor)
            {
                canCount = count;
            }
            else
            {
                canCount = 1;
            }

            bool pickupSuccess = false;

            if (canCount > 0 && !string.IsNullOrEmpty(action.name))
            {
                PlayerAnimationAction.DoAnimation(room.RoomContexts, PlayerAnimationAction.Interrupt, fd.Player, true);
                PlayerAnimationAction.DoAnimation(room.RoomContexts, PlayerAnimationAction.PickUp, fd.Player, true);
                PlayerStateUtil.AddPlayerState(EPlayerGameState.InterruptItem, fd.Player.gamePlay);

                if (!string.IsNullOrEmpty(action.key))
                {
                    action.count = canCount.ToString();
                    action.SetPlayer("current");
                    room.ContextsWrapper.FreeArgs.TempUse("current", fd);
                    action.Act(room.ContextsWrapper.FreeArgs);
                    room.ContextsWrapper.FreeArgs.Resume("current");

                    if (count > canCount)
                    {
                        SimpleProto msg = FreePool.Allocate();
                        msg.Key = FreeMessageConstant.ChickenTip;
                        msg.Ss.Add("word80," + count + "," + canCount);
                        FreeMessageSender.SendMessage(fd.Player, msg);
                        room.ContextsWrapper.FreeArgs.GameContext.session.entityFactoryObject.SceneObjectEntityFactory.CreateSimpleObjectEntity((ECategory)item.cat,
                                                                                                                                                item.id, count - canCount, entity == null ? freeMoveEntity.position.Value : entity.position.Value);
                    }
                    pickupSuccess = true;
                }
                else
                {
                    Debug.LogError(item.cat + "-" + item.key + " not existed");
                }

                if (entity != null)
                {
                    entity.isFlagDestroy = true;
                }
                if (freeMoveEntity != null)
                {
                    freeMoveEntity.isFlagDestroy = true;
                    if (freeMoveEntity.freeData.Cat == FreeEntityConstant.DeadBox)
                    {
                        var deadBox = room.ContextsWrapper.FreeArgs.GameContext.freeMove.GetEntityWithEntityKey(new EntityKey(freeMoveEntity.freeData.IntValue, (short)EEntityType.FreeMove));
                        if (deadBox != null && deadBox.freeData.EmptyDelete)
                        {
                            if (deadBox.freeData.IntValue > 1)
                            {
                                deadBox.freeData.IntValue--;
                            }
                            else
                            {
                                deadBox.isFlagDestroy = true;
                            }
                        }
                    }
                }
            }
            room.ContextsWrapper.FreeArgs.Resume("current");

            return(pickupSuccess);
        }
コード例 #11
0
        private void redrawPart(ItemInventory inventory, ISkillArgs args, ItemPosition ip, FreeData fd)
        {
            if (inventory.name == ChickenConstant.BagPrimeWeapon || inventory.name == ChickenConstant.BagSecondaryWeapon || inventory.name == ChickenConstant.BagPistolWeapon)
            {
                int id = (int)((IntPara)ip.GetParameters().Get("itemId")).GetValue();

                WeaponAllConfigs configs = SingletonManager.Get <WeaponConfigManagement>().FindConfigById(id);
                if (configs != null)
                {
                    HashSet <int> list = new HashSet <int>();

                    foreach (XmlConfig.EWeaponPartType part in configs.ApplyPartsSlot)
                    {
                        list.Add(FreeWeaponUtil.GetWeaponPart(part));
                    }

                    List <string> showP = new List <string>();
                    List <string> hideP = new List <string>();

                    for (int i = 1; i <= 5; i++)
                    {
                        if (list.Contains(i))
                        {
                            showP.Add(i.ToString());
                        }
                        else
                        {
                            hideP.Add(i.ToString());
                        }
                    }

                    ShowPartAction show = new ShowPartAction();
                    show.show = true;
                    show.SetPlayer("current");
                    show.SetScope(1);
                    if (inventory.name == ChickenConstant.BagPrimeWeapon)
                    {
                        show.weaponKey = "1";
                    }
                    else if (inventory.name == ChickenConstant.BagSecondaryWeapon)
                    {
                        show.weaponKey = "2";
                    }
                    else
                    {
                        show.weaponKey = "3";
                    }

                    show.parts = StringUtil.GetStringFromStrings(showP, ",");
                    show.Act(args);

                    show.show  = false;
                    show.parts = StringUtil.GetStringFromStrings(hideP, ",");
                    show.Act(args);
                }
                else
                {
                    Debug.LogError(ip.key.GetName() + " 没有定义配件.");
                }
            }
        }