public override void DoAction(IEventArgs args)
        {
            PlayerEntity    playerEntity = GetPlayerEntity(args);
            int             index        = FreeUtil.ReplaceInt(weaponKey, args);
            EWeaponSlotType st           = FreeWeaponUtil.GetSlotType(index);
            SimpleProto     message      = FreePool.Allocate();

            message.Key = FreeMessageConstant.ChangeWeapon;
            switch (st)
            {
            case EWeaponSlotType.None:
                playerEntity.WeaponController().UnArmWeapon(false);
                message.Ins.Add(0);
                break;

            default:
                playerEntity.WeaponController().PureSwitchIn(st);
                message.Ins.Add(index);
                break;
            }
            FreeMessageSender.SendMessage(playerEntity, message);
        }
Example #2
0
        public override void DoAction(IEventArgs args)
        {
            FreeRuleEventArgs fr = (FreeRuleEventArgs)args;

            IGameUnit unit = GetPlayer(args);

            if (unit != null)
            {
                PlayerEntity p = ((FreeData)unit).Player;

                int             itemId = FreeUtil.ReplaceInt(weaponId, args);
                int             index  = FreeUtil.ReplaceInt(weaponKey, args);
                EWeaponSlotType st     = FreeWeaponUtil.GetSlotType(index);

                WeaponBaseAgent agent = null;
                if (index == 0)
                {
                    agent = p.WeaponController().HeldWeaponAgent;
                }
                else
                {
                    agent = p.WeaponController().GetWeaponAgent(st);
                }
                if (agent != null && agent.IsValid() && !FreeUtil.ReplaceBool(replace, args))
                {
                    return;
                }

                SimpleProto message = new SimpleProto();
                var         scan    = WeaponUtil.CreateScan(itemId);
                if (FreeUtil.ReplaceBool(fullAmmo, args))
                {
                    var weaponAllConfig = SingletonManager.Get <WeaponConfigManagement>().FindConfigById(itemId);
                    scan.Bullet         = weaponAllConfig.PropertyCfg.Bullet;
                    scan.ReservedBullet = weaponAllConfig.PropertyCfg.Bulletmax;
                }
                if (index == 0)
                {
                    p.WeaponController().PickUpWeapon(scan);
                }
                else
                {
                    p.WeaponController().ReplaceWeaponToSlot(st, scan);
                    if (p.stateInterface.State.CanDraw() && p.WeaponController().HeldSlotType == EWeaponSlotType.None)
                    {
                        p.WeaponController().TryArmWeaponImmediately(st);
                    }
                }


                message.Ins.Add(itemId);
                if (index > 0)
                {
                    message.Ins.Add((int)st);
                }
                else
                {
                    message.Ins.Add(-1);
                }

                message.Ks.Add(2);
                message.Key = FreeMessageConstant.ChangeAvatar;
                FreeMessageSender.SendMessage(p, message);
                //p.network.NetworkChannel.SendReliable((int)EServer2ClientMessage.FreeData, message);
            }
        }