Example #1
0
        Unit ServerOrSingle_CreatePlayerUnit(PlayerManager.ServerOrSingle_Player player)
        {
            SpawnPoint spawnPoint = SpawnPoint.GetDefaultSpawnPoint();

            if (spawnPoint == null)
            {
                spawnPoint = SpawnPoint.GetFreeRandomSpawnPoint();
            }

            if (spawnPoint == null)
            {
                return(null);
            }
            return(ServerOrSingle_CreatePlayerUnit(player, spawnPoint));
        }
Example #2
0
        protected override void OnDie(MapObject prejudicial)
        {
            base.OnDie(prejudicial);

            //frag counter (for network games).
            if ((EntitySystemWorld.Instance.IsServer() || EntitySystemWorld.Instance.IsSingle()) &&
                PlayerManager.Instance != null)
            {
                Unit sourceUnit = null;
                {
                    Bullet bullet = prejudicial as Bullet;
                    if (bullet != null)
                    {
                        sourceUnit = bullet.SourceUnit;
                    }
                    Explosion explosion = prejudicial as Explosion;
                    if (explosion != null)
                    {
                        sourceUnit = explosion.SourceUnit;
                    }
                }

                if (sourceUnit != null)
                {
                    if (sourceUnit.Intellect != null)
                    {
                        PlayerManager.ServerOrSingle_Player player = PlayerManager.Instance.
                                                                     ServerOrSingle_GetPlayer(sourceUnit.Intellect);
                        if (player != null)
                        {
                            player.Frags++;
                        }
                    }
                }
                else
                {
                    if (Intellect != null)
                    {
                        PlayerManager.ServerOrSingle_Player player = PlayerManager.Instance.
                                                                     ServerOrSingle_GetPlayer(Intellect);
                        if (player != null)
                        {
                            player.Frags--;
                        }
                    }
                }
            }
        }
        bool Server_CheckRemoteEntityWorldAssociatedWithThisIntellect(RemoteEntityWorld sender)
        {
            UserManagementServerNetworkService.UserInfo senderUser =
                ((EntitySystemServerNetworkService.ClientRemoteEntityWorld)sender).User;

            if (PlayerManager.Instance != null)
            {
                PlayerManager.ServerOrSingle_Player player = PlayerManager.Instance.
                                                             ServerOrSingle_GetPlayer(this);

                if (senderUser != player.User)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #4
0
        Unit ServerOrSingle_CreatePlayerUnit(PlayerManager.ServerOrSingle_Player player,
                                             MapObject spawnPoint)
        {
            string unitTypeName;

            if (!player.Bot)
            {
                if (GameMap.Instance.PlayerUnitType != null)
                {
                    unitTypeName = GameMap.Instance.PlayerUnitType.Name;
                }
                else
                {
                    unitTypeName = "Girl";
                }
            }
            else
            {
                unitTypeName = player.Name;
            }

            Unit unit = (Unit)Entities.Instance.Create(unitTypeName, Map.Instance);

            Vec3 posOffset = new Vec3(0, 0, 1.5f);

            unit.Position = spawnPoint.Position + posOffset;
            unit.Rotation = spawnPoint.Rotation;
            unit.PostCreate();

            if (player.Intellect != null)
            {
                player.Intellect.ControlledObject = unit;
                unit.SetIntellect(player.Intellect, false);
            }

            Teleporter teleporter = spawnPoint as Teleporter;

            if (teleporter != null)
            {
                teleporter.ReceiveObject(unit, null);
            }

            return(unit);
        }
Example #5
0
        protected override void OnDamage(MapObject prejudicial,
                                         Vec3 pos, Shape shape, float damage, bool allowMoveDamageToParent)
        {
            base.OnDamage(prejudicial, pos, shape, damage, allowMoveDamageToParent);

            if ((EntitySystemWorld.Instance.IsServer() || EntitySystemWorld.Instance.IsSingle()) &&
                PlayerManager.Instance != null)
            {
                Unit sourceUnit         = null;
                int  hitPointMultiplier = 1;
                {
                    Bullet bullet = prejudicial as Bullet;
                    if (bullet != null)
                    {
                        sourceUnit = bullet.SourceUnit;
                        //reward bullet hits with extra points. explsions are for lamers
                        hitPointMultiplier = bullet.Type.HitPointMultiplier;
                    }
                    Explosion explosion = prejudicial as Explosion;
                    if (explosion != null)
                    {
                        sourceUnit = explosion.SourceUnit;
                    }
                }

                if (sourceUnit != null)
                {
                    if (sourceUnit.Intellect != null)
                    {
                        PlayerManager.ServerOrSingle_Player player = PlayerManager.Instance.
                                                                     ServerOrSingle_GetPlayer(sourceUnit.Intellect);
                        if (player != null)
                        {
                            player.HitPoints += (Type.PointsForHit * hitPointMultiplier);
                        }
                    }
                }
            }
        }
        private Vec2 GetMovementByControlKeys()
        {
            Vec2 localVector = Vec2.Zero;

            if (EntitySystemWorld.Instance.IsServer() || EntitySystemWorld.Instance.IsDedicatedServer())
            {
                PlayerManager.ServerOrSingle_Player player = null;
                player = PlayerManager.Instance.ServerOrSingle_GetPlayer(Intellect);
                if (GameMap.Instance != null && player.Intellect == Intellect)                  //PlayerIntellect.Instance == Intellect)
                {
                    localVector.X -= Intellect.GetControlKeyStrength(GameControlKeys.Forward);  // +this.Type.SpeedForward;
                    localVector.X += Intellect.GetControlKeyStrength(GameControlKeys.Backward); // +this.Type.SpeedBackward;
                    localVector.Y -= Intellect.GetControlKeyStrength(GameControlKeys.Left);     // +this.Type.SpeedLeft;
                    localVector.Y += Intellect.GetControlKeyStrength(GameControlKeys.Right);    // +this.Type.SpeedRight;

                    if (localVector != Vec2.Zero)
                    {
                        Vec2   diff     = Position.ToVec2() - TurnToPosition.ToVec2();;// *Rotation.GetForward().ToVec2();//RendererWorld.Instance.DefaultCamera.Position.ToVec2();
                        Degree angle    = new Radian(MathFunctions.ATan(diff.Y, diff.X));
                        Degree vecAngle = new Radian(MathFunctions.ATan(-localVector.Y, localVector.X));
                        Quat   rot      = new Angles(0, 0, vecAngle - angle).ToQuat();
                        Vec2   vector   = (rot * new Vec3(1, 0, 0)).ToVec2();
                        return(vector);
                    }
                    else
                    {
                        return(Vec2.Zero);
                    }
                }
                return(Vec2.Zero);
            }
            else if (EntitySystemWorld.Instance.IsSingle())
            {
                if (GameMap.Instance != null && PlayerIntellect.Instance == Intellect)
                {
                    localVector.X -= Intellect.GetControlKeyStrength(GameControlKeys.Forward);  // +this.Type.SpeedForward;
                    localVector.X += Intellect.GetControlKeyStrength(GameControlKeys.Backward); // +this.Type.SpeedBackward;
                    localVector.Y -= Intellect.GetControlKeyStrength(GameControlKeys.Left);     // +this.Type.SpeedLeft;
                    localVector.Y += Intellect.GetControlKeyStrength(GameControlKeys.Right);    // +this.Type.SpeedRight;

                    if (localVector != Vec2.Zero)
                    {
                        Vec2   diff     = Position.ToVec2() - TurnToPosition.ToVec2();;// *Rotation.GetForward().ToVec2();//RendererWorld.Instance.DefaultCamera.Position.ToVec2();
                        Degree angle    = new Radian(MathFunctions.ATan(diff.Y, diff.X));
                        Degree vecAngle = new Radian(MathFunctions.ATan(-localVector.Y, localVector.X));
                        Quat   rot      = new Angles(0, 0, vecAngle - angle).ToQuat();
                        Vec2   vector   = (rot * new Vec3(1, 0, 0)).ToVec2();
                        return(vector);
                    }
                    else
                    {
                        return(Vec2.Zero);
                    }
                }
                return(Vec2.Zero);
            }
            return(Vec2.Zero);
            ////    if (localVector != Vec2.Zero)
            ////    {
            ////        localVector.Normalize();

            ////        //calculate force vector with considering camera orientation
            ////        Vec2 diff = Position.ToVec2() - RendererWorld.Instance.DefaultCamera.Position.ToVec2();
            ////        //new Vec3( RendererWorld.Instance.DefaultCamera.Position.X,RendererWorld.Instance.DefaultCamera.Position.Y, Damager_Ball_Player.Position.Z);
            ////        //diff.Z += this.Type.BallRadius;

            ////        Degree angle = new Radian(MathFunctions.ATan(diff.Y, diff.X));
            ////        Degree vecAngle = new Radian(MathFunctions.ATan(-vec.Y, vec.X));
            ////        Quat rot = new Angles(0, 0, vecAngle - angle).ToQuat();

            ////        Vec2 forceVector2 = (rot * new Vec3(1, 0, 0)).ToVec2();

            ////        Vec2 forceVector = new Vec2(forceVector2.X, forceVector2.Y);

            ////        return forceVector;
            ////    }
            ////    else return vec;
            ////}
            ////else
            ////    return vec;
        }
Example #7
0
        /// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnTick()"/>.</summary>
        protected override void OnTick()
        {
            base.OnTick();

            //single mode. recreate player units if need
            if (EntitySystemWorld.Instance.IsSingle())
            {
                if (GameMap.Instance.GameType == GameMap.GameTypes.Action ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TPSArcade ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TurretDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.VillageDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.PlatformerDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights)
                {
                    if (PlayerManager.Instance != null)
                    {
                        foreach (PlayerManager.ServerOrSingle_Player player in
                                 PlayerManager.Instance.ServerOrSingle_Players)
                        {
                            if (player.Intellect == null || player.Intellect.ControlledObject == null)
                            {
                                ServerOrSingle_CreatePlayerUnit(player);
                            }
                        }
                    }
                }
            }

            //networking mode
            if (EntitySystemWorld.Instance.IsServer())
            {
                if (GameMap.Instance.GameType == GameMap.GameTypes.Action ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TPSArcade ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TurretDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.VillageDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.PlatformerDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights) //iNCIN -- OK NOW
                {
                    if (PlayerManager.Instance != null)
                    {
                        UserManagementServerNetworkService userManagementService =
                            GameNetworkServer.Instance.UserManagementService;

                        //remove users
again:
                        foreach (PlayerManager.ServerOrSingle_Player player in
                                 PlayerManager.Instance.ServerOrSingle_Players)
                        {
                            if (player.User != null && player.User != userManagementService.ServerUser)
                            {
                                NetworkNode.ConnectedNode connectedNode = player.User.ConnectedNode;
                                if (connectedNode == null ||
                                    connectedNode.Status != NetworkConnectionStatuses.Connected)
                                {
                                    if (player.Intellect != null)
                                    {
                                        PlayerIntellect playerIntellect = player.Intellect as PlayerIntellect;
                                        if (playerIntellect != null)
                                        {
                                            playerIntellect.TryToRestoreMainControlledUnit();
                                        }

                                        if (player.Intellect.ControlledObject != null)
                                        {
                                            player.Intellect.ControlledObject.Die();
                                        }
                                        player.Intellect.SetForDeletion(true);
                                        player.Intellect = null;
                                    }

                                    PlayerManager.Instance.ServerOrSingle_RemovePlayer(player);

                                    goto again;
                                }
                            }
                        }

                        //add users
                        foreach (UserManagementServerNetworkService.UserInfo user in
                                 userManagementService.Users)
                        {
                            //check whether "EntitySystem" service on the client
                            if (user.ConnectedNode != null)
                            {
                                if (!user.ConnectedNode.RemoteServices.Contains("EntitySystem"))
                                {
                                    continue;
                                }
                            }

                            PlayerManager.ServerOrSingle_Player player = PlayerManager.Instance.
                                                                         ServerOrSingle_GetPlayer(user);

                            if (player == null)
                            {
                                player = PlayerManager.Instance.Server_AddClientPlayer(user);

                                PlayerIntellect intellect = (PlayerIntellect)Entities.Instance.
                                                            Create("PlayerIntellect", World.Instance);
                                intellect.PostCreate();

                                player.Intellect = intellect;

                                if (GameNetworkServer.Instance.UserManagementService.ServerUser != user)
                                {
                                    //player on client
                                    RemoteEntityWorld remoteEntityWorld = GameNetworkServer.Instance.
                                                                          EntitySystemService.GetRemoteEntityWorld(user);
                                    intellect.Server_SendSetInstanceToClient(remoteEntityWorld);
                                }
                                else
                                {
                                    //player on this server
                                    PlayerIntellect.SetInstance(intellect);
                                }

                                //player.Intellect = intellect;
                                if (player.User.Faction == null)
                                {
                                    return;
                                }
                                FactionType f = (FactionType)EntityTypes.Instance.GetByName(player.User.Faction);
                                player.Intellect.Faction = f;
                            }
                        }

                        //create units
                        foreach (PlayerManager.ServerOrSingle_Player player in
                                 PlayerManager.Instance.ServerOrSingle_Players)
                        {
                            if (player.Intellect != null && player.Intellect.ControlledObject == null)
                            {
                                if (GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights)
                                {
                                    ServerOrSingle_CreatePlayerUnit(player);
                                }
                                else
                                {
                                    ServerOrSingle_CreatePlayerUnit(player);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #8
0
        private Unit ServerOrSingle_CreatePlayerUnit(PlayerManager.ServerOrSingle_Player player,
                                                     MapObject spawnPoint)
        {
            string unitTypeName;

            if (!player.Bot)
            {
                if (player.Intellect.Faction.Name == "AssaultKnights" && GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights)
                {
                    unitTypeName = "AKSoldier";
                }
                else if (player.Intellect.Faction.Name == "Omni" && GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights)
                {
                    unitTypeName = "OmniSoldier";
                }
                else if (GameMap.Instance.PlayerUnitType != null)
                {
                    unitTypeName = GameMap.Instance.PlayerUnitType.Name;
                }
                else
                {
                    unitTypeName = "Girl";
                }
            }
            else if (player.Bot)
            {
                unitTypeName = player.Name;
            }
            else
            {
                unitTypeName = "Rabbit";
            }

            Unit unit = (Unit)Entities.Instance.Create(unitTypeName, Map.Instance);

            Vec3 posOffset = new Vec3(0, 0, 1.5f);

            unit.Position = spawnPoint.Position + posOffset;
            unit.Rotation = spawnPoint.Rotation;
            unit.PostCreate();

            if (player.Intellect != null)
            {
                player.Intellect.ControlledObject = unit;
                unit.SetIntellect(player.Intellect, false);
            }

            Teleporter teleporter = spawnPoint as Teleporter;

            if (teleporter != null)
            {
                teleporter.ReceiveObject(unit, null);
            }

            //Incin -- Custom Box teleporter
            BoxTeleporter boxteleporter = spawnPoint as BoxTeleporter;

            if (boxteleporter != null)
            {
                boxteleporter.ReceiveObject(unit, null);
            }

            return(unit);
        }
Example #9
0
        //original 1.32 code -- Incin
        private Unit ServerOrSingle_CreatePlayerUnit(PlayerManager.ServerOrSingle_Player player)
        {
            SpawnPoint spawnPoint = null;

            if (GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights)
            {
                List <SpawnPoint> instancePoints = SpawnPoint.Instances();
                foreach (SpawnPoint sp in instancePoints)
                {
                    if (sp == null || sp.Faction == null) //Incin -- additional check
                    {
                        return(null);
                    }

                    if (sp.Faction != player.Intellect.Faction)
                    {
                        continue;
                    }
                    if (sp.SpawnID != (SpawnPoint.SpawnId)player.User.SpawnId)
                    {
                        continue;
                    }
                    //spawnPoint = SpawnPoint.GetDefaultSpawnPoint();
                    spawnPoint = sp;

                    if (spawnPoint != null)
                    {
                        return(ServerOrSingle_CreatePlayerUnit(player, spawnPoint));
                    }

                    ////Other Game Modes
                    //if (spawnPoint == null)
                    //    spawnPoint = SpawnPoint.GetDefaultSpawnPoint();

                    //if (spawnPoint == null)
                    //    spawnPoint = SpawnPoint.GetFreeRandomSpawnPoint();

                    if (spawnPoint == null)
                    {
                        return(null);
                    }

                    return(ServerOrSingle_CreatePlayerUnit(player, spawnPoint));
                }
            }
            else
            {
                //Other Game Modes
                if (spawnPoint == null)
                {
                    spawnPoint = SpawnPoint.GetDefaultSpawnPoint();
                }

                if (spawnPoint == null)
                {
                    spawnPoint = SpawnPoint.GetFreeRandomSpawnPoint();
                }

                if (spawnPoint == null)
                {
                    return(null);
                }

                return(ServerOrSingle_CreatePlayerUnit(player, spawnPoint));
            }

            return(null);
        }
Example #10
0
        internal void DoActionsAfterMapCreated()
        {
            if (EntitySystemWorld.Instance.IsSingle())
            {
                if (GameMap.Instance.GameType == GameMap.GameTypes.Action ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TPSArcade ||
                    GameMap.Instance.GameType == GameMap.GameTypes.TurretDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.VillageDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.PlatformerDemo ||
                    GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights)
                {
                    string playerName = "__SinglePlayer__";

                    //create Player
                    PlayerManager.ServerOrSingle_Player player = PlayerManager.Instance.
                                                                 ServerOrSingle_GetPlayer(playerName);
                    if (player == null)
                    {
                        player = PlayerManager.Instance.Single_AddSinglePlayer(playerName);
                    }

                    //create PlayerIntellect
                    PlayerIntellect intellect = null;
                    {
                        //find already created PlayerIntellect
                        foreach (Entity entity in World.Instance.Children)
                        {
                            intellect = entity as PlayerIntellect;
                            if (intellect != null)
                            {
                                break;
                            }
                        }

                        if (intellect == null)
                        {
                            intellect = (PlayerIntellect)Entities.Instance.Create("PlayerIntellect",
                                                                                  World.Instance);
                            intellect.PostCreate();

                            player.Intellect = intellect;
                        }

                        //set instance
                        if (PlayerIntellect.Instance == null)
                        {
                            PlayerIntellect.SetInstance(intellect);
                        }
                    }

                    //create unit
                    if (intellect.ControlledObject == null)
                    {
                        MapObject spawnPoint = null;
                        if (!string.IsNullOrEmpty(needChangeMapSpawnPointName))
                        {
                            spawnPoint = Entities.Instance.GetByName(needChangeMapSpawnPointName) as MapObject;
                            if (spawnPoint == null)
                            {
                                Log.Warning("GameWorld: Object with name \"{0}\" does not exist.",
                                            needChangeMapSpawnPointName);
                            }
                        }

                        Unit unit;
                        if (spawnPoint != null)
                        {
                            unit = ServerOrSingle_CreatePlayerUnit(player, spawnPoint);
                        }
                        else
                        {
                            unit = ServerOrSingle_CreatePlayerUnit(player);
                        }

                        if (needChangeMapPlayerCharacterInformation != null)
                        {
                            PlayerCharacter playerCharacter = (PlayerCharacter)unit;
                            playerCharacter.ApplyChangeMapInformation(
                                needChangeMapPlayerCharacterInformation, spawnPoint);
                        }
                        else
                        {
                            if (unit != null)
                            {
                                intellect.LookDirection = SphereDir.FromVector(
                                    unit.Rotation.GetForward());
                            }
                        }
                    }
                }
            }

            needChangeMapName                       = null;
            needChangeMapSpawnPointName             = null;
            needChangeMapPlayerCharacterInformation = null;
        }
Example #11
0
        protected override void OnDie(MapObject prejudicial)
        {
            base.OnDie(prejudicial);

            //frag counter (for network games).
            if ((EntitySystemWorld.Instance.IsServer() || EntitySystemWorld.Instance.IsSingle()) &&
                PlayerManager.Instance != null)
            {
                Unit sourceUnit              = null;
                int  killPointMultiplier     = 1;
                int  assaultCreditMultiplier = 1;
                {
                    Bullet bullet = prejudicial as Bullet;
                    if (bullet != null)
                    {
                        sourceUnit = bullet.SourceUnit;
                        //again, bullet kills get the goodies. explosions don't require skill, just luck
                        killPointMultiplier     = bullet.Type.KillPointMultiplier;
                        assaultCreditMultiplier = bullet.Type.AssaultCreditMultiplier;
                    }
                    Explosion explosion = prejudicial as Explosion;
                    if (explosion != null)
                    {
                        sourceUnit = explosion.SourceUnit;
                    }
                }

                if (sourceUnit != null)
                {
                    if (sourceUnit.Intellect != null)
                    {
                        PlayerManager.ServerOrSingle_Player player = PlayerManager.Instance.
                                                                     ServerOrSingle_GetPlayer(sourceUnit.Intellect);
                        if (player != null && GameMap.Instance.GameType != GameMap.GameTypes.AssaultKnights)
                        {
                            player.Frags++;
                        }
                        else if (player != null && GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights)
                        {
                            player.KillPoints     += (Type.PointsForKill * killPointMultiplier);
                            player.AssaultCredits += ((Type.AssaultCredits * assaultCreditMultiplier) * player.KillPoints);
                        }
                        else
                        {
                            Log.Info("wtf");
                        }
                    }
                }
                else if (GameMap.Instance.GameType != GameMap.GameTypes.AssaultKnights)
                {
                    if (Intellect != null)
                    {
                        PlayerManager.ServerOrSingle_Player player = PlayerManager.Instance.
                                                                     ServerOrSingle_GetPlayer(Intellect);
                        if (player != null)
                        {
                            player.Frags--;
                        }
                    }
                }
                else if (GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights)
                {
                    if (Intellect != null)
                    {
                        PlayerManager.ServerOrSingle_Player player = PlayerManager.Instance.
                                                                     ServerOrSingle_GetPlayer(Intellect);
                        if (player != null)
                        {
                            player.Frags--;
                        }
                    }
                }
            }
        }