Beispiel #1
0
        public void Trigger(int eventId, TempUnit unit)
        {
            triggerArgs.Reset();
            triggerArgs.AddUnit(unit.key, unit.unit);

            triggerArgs.Trigger(this, _triggers, eventId);
        }
Beispiel #2
0
        public void Trigger(int eventId, params TempUnit[] units)
        {
            triggerArgs.Reset();
            for (int i = 0; i < units.Length; i++)
            {
                triggerArgs.AddUnit(units[i]);
            }

            triggerArgs.Trigger(this, _triggers, eventId);
        }
Beispiel #3
0
        public void AutoPickupWeapon(PlayerEntity player, int sceneKey)
        {
            SceneObjectEntity sceneEntity = sceneObjectEntityFactory.GetSceneEntity(sceneKey) as SceneObjectEntity;

            if (sceneEntity == null || !sceneEntity.IsCanPickUpByPlayer(player))
            {
                return;
            }
            var  newWeaponScan = (WeaponScanStruct)sceneEntity.weaponObject;
            bool pickupResult  = player.WeaponController().AutoPickUpWeapon(newWeaponScan);

            if (!pickupResult)
            {
                return;
            }
            sceneObjectEntityFactory.DestroySceneWeaponObjectEntity(sceneEntity.entityKey.Value);
            IEventArgs args = commonSession.FreeArgs as IEventArgs;

            if (null != args)
            {
                TriggerArgs ta = new TriggerArgs();
                ta.AddPara(new IntPara("weaponId", sceneEntity.weaponObject.ConfigId));
                ta.AddUnit("current", (FreeData)player.freeData.FreeData);
                args.Trigger(FreeTriggerConstant.WEAPON_PICKUP, ta);
            }
        }
Beispiel #4
0
        public override void DoAction(IEventArgs args)
        {
            var contexts = args.GameContext;
            var player   = GetPlayerEntity(args);

            var  factory          = contexts.session.entityFactoryObject.SceneObjectEntityFactory;
            var  slot             = (EWeaponSlotType)slotIndex;
            var  lastWeaponScan   = player.WeaponController().GetWeaponAgent(slot).ComponentScan;
            bool generateSceneObj = player.WeaponController().DropWeapon(slot);

            //     var lastWeaponScan = player.WeaponController().HeldWeaponAgent.ComponentScan;
            if (!generateSceneObj || lastWeaponScan.IsUnSafeOrEmpty())
            {
                return;
            }
            var unitPos = pos.Select(args);
            var weapon  = factory.CreateDropSceneWeaponObjectEntity(lastWeaponScan, new UnityEngine.Vector3(unitPos.GetX(), unitPos.GetY(), unitPos.GetZ()), args.GetInt(lifeTime)) as SceneObjectEntity;

            if (null != weapon)
            {
                TriggerArgs ta = new TriggerArgs();
                ta.AddPara(new IntPara("weaponId", lastWeaponScan.ConfigId));
                ta.AddPara(new FloatPara("weaponx", weapon.position.Value.x));
                ta.AddPara(new FloatPara("weapony", weapon.position.Value.y));
                ta.AddPara(new FloatPara("weaponz", weapon.position.Value.z));
                ta.AddUnit("current", (FreeData)player.freeData.FreeData);
                args.Trigger(FreeTriggerConstant.WEAPON_DROP, ta);
            }
        }
Beispiel #5
0
        public virtual void AutoPickupWeapon(PlayerEntity player, List <int> sceneKeys)
        {
            for (int i = 0; i < sceneKeys.Count; i++)
            {
                SceneObjectEntity sceneEntity = sceneObjectEntityFactory.GetSceneEntity(sceneKeys[i]) as SceneObjectEntity;
                //sceneKeys.Remove(sceneKeys[i]);
                if (sceneEntity == null || !sceneEntity.hasWeaponObject)
                {
                    Logger.Warn("sceneEntity null failed");
                    return;
                }

                EWeaponType_Config configType = (EWeaponType_Config)SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(sceneEntity.weaponObject.ConfigId).Type;
                if (!configType.CanAutoPick())
                {
                    Logger.Warn("CanAutoPick failed");
                    return;
                }
                if (configType == EWeaponType_Config.TacticWeapon && !sceneEntity.IsCanPickUpByPlayer(player))
                {
                    Logger.Warn("IsCanPickUpByPlayer failed");
                    return;
                }

                var  newWeaponScan = (WeaponScanStruct)sceneEntity.weaponObject;
                bool pickupResult  = player.WeaponController().AutoPickUpWeapon(newWeaponScan);
                if (!pickupResult)
                {
                    Logger.Warn("pickupResult failed");
                    return;
                }

                sceneObjectEntityFactory.DestroySceneWeaponObjectEntity(sceneEntity.entityKey.Value);
                if (player.WeaponController().HeldConfigId == sceneEntity.weaponObject.ConfigId)
                {
                    player.stateInterface.State.PickUp();
                }

                IEventArgs args = commonSession.FreeArgs as IEventArgs;
                if (null != args)
                {
                    TriggerArgs ta = new TriggerArgs();
                    ta.AddPara(new IntPara("weaponId", sceneEntity.weaponObject.ConfigId));
                    ta.AddUnit("current", (FreeData)player.freeData.FreeData);
                    args.Trigger(FreeTriggerConstant.WEAPON_PICKUP, ta);
                }
            }
        }
        public void AutoPickupWeapon(PlayerEntity player, List <int> sceneKeys)
        {
            for (int i = 0; i < sceneKeys.Count; i++)
            {
                SceneObjectEntity sceneEntity = sceneObjectEntityFactory.GetSceneEntity(sceneKeys[i]) as SceneObjectEntity;
                if (sceneEntity == null || !sceneEntity.hasWeaponObject || sceneEntity.isFlagDestroy)
                {
                    continue;
                }

                EWeaponType_Config configType = (EWeaponType_Config)SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(sceneEntity.weaponObject.ConfigId).Type;
                if (!configType.CanAutoPick())
                {
                    continue;
                }

                if (configType == EWeaponType_Config.TacticWeapon && !sceneEntity.IsCanPickUpByPlayer(player))
                {
                    continue;
                }

                var  newWeaponScan = (WeaponScanStruct)sceneEntity.weaponObject;
                bool pickupResult  = player.WeaponController().AutoPickUpWeapon(newWeaponScan);
                if (!pickupResult)
                {
                    continue;
                }

                sceneObjectEntityFactory.DestroySceneWeaponObjectEntity(sceneEntity.entityKey.Value);

                if (player.WeaponController().HeldConfigId == sceneEntity.weaponObject.ConfigId && SharedConfig.IsServer)
                {
                    PlayerAnimationAction.DoAnimation(null, PlayerAnimationAction.PickUp, player, true);
                }

                IEventArgs args = commonSession.FreeArgs as IEventArgs;
                if (null != args)
                {
                    TriggerArgs ta = new TriggerArgs();
                    ta.AddPara(new IntPara("weaponId", sceneEntity.weaponObject.ConfigId));
                    ta.AddUnit("current", (FreeData)player.freeData.FreeData);
                    args.Trigger(FreeTriggerConstant.WEAPON_PICKUP, ta);
                }
            }
        }
Beispiel #7
0
        public override void DoPickup(PlayerEntity player, int sceneKey)
        {
            var sceneEntity = sceneObjectEntityFactory.GetSceneEntity(sceneKey) as SceneObjectEntity;

            if (sceneEntity == null || sceneEntity.hasThrowing || !sceneEntity.hasWeaponObject || !sceneEntity.IsCanPickUpByPlayer(player) || sceneEntity.isFlagDestroy)
            {
                Logger.ErrorFormat("only weapon is supported in normal mode");
                return;
            }
            var controller = player.WeaponController();

            //销毁场景武实体
            sceneObjectEntityFactory.DestroySceneWeaponObjectEntity(sceneEntity.entityKey.Value);
            var        lastWeaponScan   = controller.GetWeaponAgent(sceneEntity.weaponObject.ConfigId).ComponentScan;
            var        newWeaponScan    = (WeaponScanStruct)sceneEntity.weaponObject;
            bool       pickupSuccess    = false;
            bool       generateSceneObj = controller.PickUpWeapon(newWeaponScan, ref pickupSuccess);
            IEventArgs args             = commonSession.FreeArgs as IEventArgs;

            if (pickupSuccess && null != args)
            {
                TriggerArgs ta = new TriggerArgs();
                ta.AddPara(new IntPara("weaponId", newWeaponScan.ConfigId));
                ta.AddUnit("current", (FreeData)player.freeData.FreeData);
                args.Trigger(FreeTriggerConstant.WEAPON_PICKUP, ta);
            }

            if (!generateSceneObj || lastWeaponScan.IsUnSafeOrEmpty())
            {
                return;
            }
            //  WeaponEntity lastEntity = WeaponEntityFactory.CreateEntity(lastWeaponScan);
            //newWeaponScan = WeaponUtil.CreateScan(lastEntity);
            sceneObjectEntityFactory.CreateDropSceneWeaponObjectEntity(lastWeaponScan, player.position.Value, sceneWeaponLifeTime);
            if (null != args)
            {
                TriggerArgs ta = new TriggerArgs();
                ta.AddPara(new IntPara("weaponId", lastWeaponScan.ConfigId));
                ta.AddUnit("current", (FreeData)player.freeData.FreeData);
                ta.AddPara(new FloatPara("weaponx", player.position.Value.x));
                ta.AddPara(new FloatPara("weapony", player.position.Value.y));
                ta.AddPara(new FloatPara("weaponz", player.position.Value.z));
                args.Trigger(FreeTriggerConstant.WEAPON_DROP, ta);
            }
        }
        public virtual IEntity CreateDropSceneWeaponObjectEntity(WeaponScanStruct weaponScan, IEntity entity,
                                                                 int lifeTime, IFreeArgs freeArgs = null)
        {
            PlayerEntity playerEntity      = entity as PlayerEntity;
            var          dropPos           = SceneObjectDropUtil.GetDropObjectPos(playerEntity);
            var          sceneObjectEntity = CreateDropSceneWeaponObjectEntity(weaponScan, dropPos,
                                                                               lifeTime) as SceneObjectEntity;

            if (sceneObjectEntity != null && freeArgs is IEventArgs)
            {
                TriggerArgs ta     = new TriggerArgs();
                var         posVal = sceneObjectEntity.position.Value;
                ta.AddPara(new IntPara("weaponId", weaponScan.ConfigId));
                ta.AddPara(new FloatPara("weaponx", posVal.x));
                ta.AddPara(new FloatPara("weapony", posVal.y));
                ta.AddPara(new FloatPara("weaponz", posVal.z));
                ta.AddUnit("current", (FreeData)playerEntity.freeData.FreeData);
                (freeArgs as IEventArgs).Trigger(FreeTriggerConstant.WEAPON_DROP, ta);
            }

            return(sceneObjectEntity);
        }
Beispiel #9
0
        public void ExecuteUserCmd(IPlayerUserCmdGetter getter, IUserCmd cmd)
        {
            PlayerEntity myEntity = getter.OwnerEntity as PlayerEntity;

            if (null == myEntity)
            {
                return;
            }

            var myState = myEntity.stateInterface.State;

            if (myEntity.gamePlay.IsSave || myEntity.gamePlay.IsBeSave)
            {
                PlayerEntity teamEntity = _contexts.player.GetEntityWithEntityKey(myEntity.gamePlay.SavePlayerKey);
                if (null == teamEntity)
                {
                    StopSave(myEntity, true);
                    return;
                }

                if (myEntity.time.ClientTime - myEntity.gamePlay.SaveTime >= saveTime)
                {
                    if (myEntity.gamePlay.IsSave)
                    {
                        myEntity.statisticsData.Statistics.SaveCount++;
                    }
                    else
                    {
                        myEntity.statisticsData.Statistics.BeSaveCount++;
                        myEntity.gamePlay.CurHp = myEntity.gamePlay.MaxHp * 0.1f;
                        if (SharedConfig.IsServer)
                        {
                            myEntity.gamePlay.ChangeLifeState(EPlayerLifeState.Alive, myEntity.time.ClientTime);
                        }
                    }

                    try
                    {
                        var args = _contexts.session.commonSession.FreeArgs as IEventArgs;
                        if (args != null && SharedConfig.IsServer)
                        {
                            TriggerArgs ta = new TriggerArgs();
                            ta.AddUnit("savor", (FreeData)(myEntity.gamePlay.IsSave ? myEntity.freeData.FreeData : teamEntity.freeData.FreeData));
                            ta.AddUnit("saved", (FreeData)(myEntity.gamePlay.IsSave ? teamEntity.freeData.FreeData : myEntity.freeData.FreeData));
                            args.Trigger(FreeTriggerConstant.PLAYER_RESCUE_SUCCESS, ta);
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.ErrorFormat("player rescue success trigger failed", e);
                    }

                    StopSave(myEntity, false);
                    return;
                }

                if (Vector3.Distance(myEntity.position.Value, teamEntity.position.Value) > SharedConfig.MaxSaveDistance)
                {
                    StopSave(myEntity, true);
                    StopSave(teamEntity, true);
                    return;
                }

                if (myEntity.gamePlay.IsSave)
                {
                    if (!cmd.IsF || myState.NeedInterruptRescue() || !myEntity.gamePlay.IsLifeState(EPlayerLifeState.Alive) ||
                        GetAngle(myEntity, teamEntity) > SharedConfig.MaxSaveAngle)
                    {
                        StopSave(myEntity, true);
                        StopSave(teamEntity, true);
                        return;
                    }
                }
                else
                {
                    if (myEntity.gamePlay.IsDead())
                    {
                        StopSave(myEntity, true);
                        StopSave(teamEntity, true);
                        return;
                    }
                }
            }

            if (cmd.IsUseAction && cmd.UseType == (int)EUseActionType.Player && myEntity.gamePlay.IsSave == false &&
                myState.GetCurrentMovementState() == MovementInConfig.Idle &&
                myState.GetCurrentPostureState() != PostureInConfig.Land && myState.GetCurrentPostureState() != PostureInConfig.Prone)
            {
                PlayerEntity saveEntity = _contexts.player.GetEntityWithEntityKey(new EntityKey(cmd.UseEntityId, (int)EEntityType.Player));
                if (saveEntity != null && SharedConfig.IsServer)
                {
                    PlayerAnimationAction.DoAnimation(_contexts, PlayerAnimationAction.Rescue, myEntity, true);
                    myEntity.gamePlay.IsSave          = true;
                    myEntity.gamePlay.SaveTime        = myEntity.time.ClientTime;
                    myEntity.gamePlay.SavePlayerKey   = saveEntity.entityKey.Value;
                    saveEntity.gamePlay.IsBeSave      = true;
                    saveEntity.gamePlay.SaveTime      = saveEntity.time.ClientTime;
                    saveEntity.gamePlay.SavePlayerKey = myEntity.entityKey.Value;

                    SimpleProto data = FreePool.Allocate();
                    data.Key = FreeMessageConstant.CountDown;
                    data.Bs.Add(true);
                    data.Fs.Add(saveTime / 1000);
                    FreeMessageSender.SendMessage(myEntity, data);
                    FreeMessageSender.SendMessage(saveEntity, data);
                }
            }
        }
Beispiel #10
0
        public virtual void Drop(PlayerEntity player, EWeaponSlotType slot, IUserCmd cmd)
        {
            if (slot == EWeaponSlotType.ThrowingWeapon)
            {
                DoDropGrenade(player, slot, cmd);
                return;
            }
            var heldAgent = player.WeaponController().HeldWeaponAgent;

            if (heldAgent.IsValid())
            {
                var  dropPos          = player.GetHandWeaponPosition();
                var  playerTrans      = player.characterContoller.Value.transform;
                var  forward          = playerTrans.forward;
                var  pos              = dropPos + forward * runtimeGameConfig.WeaponDropOffset;
                var  weaponScacn      = heldAgent.ComponentScan;
                bool generateSceneObj = player.WeaponController().DropWeapon(slot);
                if (!generateSceneObj || weaponScacn.IsUnSafeOrEmpty())
                {
                    return;
                }
                //     DebugUtil.LogInUnity(weaponScacn.ToString(), DebugUtil.DebugColor.Black);
                RaycastHit        hhit;
                SceneObjectEntity sceneObjectEntity;
                if (Physics.Raycast(dropPos, forward, out hhit, runtimeGameConfig.WeaponDropOffset,
                                    UnityLayers.SceneCollidableLayerMask))
                {
                    RaycastHit vhit;
                    if (Physics.Raycast(hhit.point, Vector3.down, out vhit, 100, UnityLayers.SceneCollidableLayerMask))
                    {
                        sceneObjectEntity =
                            sceneObjectEntityFactory.CreateDropSceneWeaponObjectEntity(weaponScacn, vhit.point,
                                                                                       sceneWeaponLifeTime) as SceneObjectEntity;
                    }
                    else
                    {
                        sceneObjectEntity =
                            sceneObjectEntityFactory.CreateDropSceneWeaponObjectEntity(weaponScacn,
                                                                                       playerTrans.position, sceneWeaponLifeTime) as SceneObjectEntity;
                    }
                }
                else
                {
                    RaycastHit vhit;
                    if (Physics.Raycast(pos, Vector3.down, out vhit, 100, UnityLayers.SceneCollidableLayerMask))
                    {
                        sceneObjectEntity =
                            sceneObjectEntityFactory.CreateDropSceneWeaponObjectEntity(weaponScacn, vhit.point,
                                                                                       sceneWeaponLifeTime) as SceneObjectEntity;
                    }
                    else
                    {
                        sceneObjectEntity =
                            sceneObjectEntityFactory.CreateDropSceneWeaponObjectEntity(weaponScacn,
                                                                                       playerTrans.position, sceneWeaponLifeTime) as SceneObjectEntity;
                    }
                }

                IEventArgs args = commonSession.FreeArgs as IEventArgs;
                if (null != args && null != sceneObjectEntity)
                {
                    TriggerArgs ta = new TriggerArgs();
                    ta.AddPara(new IntPara("weaponId", weaponScacn.ConfigId));
                    ta.AddPara(new FloatPara("weaponx", sceneObjectEntity.position.Value.x));
                    ta.AddPara(new FloatPara("weapony", sceneObjectEntity.position.Value.y));
                    ta.AddPara(new FloatPara("weaponz", sceneObjectEntity.position.Value.z));
                    ta.AddUnit("current", (FreeData)player.freeData.FreeData);
                    args.Trigger(FreeTriggerConstant.WEAPON_DROP, ta);
                }
            }
        }