Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        private void ServerOrSingle_ChangeMainControlledUnit(Unit unit)
        {
            //Change player controlled unit
            mainNotActiveUnit = ControlledObject;

            //send mainNotActiveUnit to clients
            if (EntitySystemWorld.Instance.IsServer())
            {
                Server_SendMainNotActiveUnitToClients(EntitySystemWorld.Instance.RemoteEntityWorlds);
            }

            if (mainNotActiveUnit != null)
            {
                SubscribeToDeletionEvent(mainNotActiveUnit);

                mainNotActiveUnit.SetIntellect(null, false);
                mainNotActiveUnitRestorePosition = mainNotActiveUnit.Position;

                //disable collision for shapes and save contact groups
                mainNotActiveUnitShapeContactGroups = new Dictionary <Shape, int>();
                foreach (Body body in mainNotActiveUnit.PhysicsModel.Bodies)
                {
                    foreach (Shape shape in body.Shapes)
                    {
                        mainNotActiveUnitShapeContactGroups.Add(shape, shape.ContactGroup);
                        shape.ContactGroup = (int)ContactGroup.NoContact;
                    }
                }

                mainNotActiveUnit.Server_EnableSynchronizationPositionsToClients = false;

                ControlledObject = unit;
                unit.SetIntellect(this, false);

                if (GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights)
                {
                    unit.InitialFaction = mainNotActiveUnit.InitialFaction;
                }
                unit.Destroying += AlternativeUnitAllowPlayerControl_Destroying;
            }
        }
        void ServerOrSingle_RestoreMainControlledUnit()
        {
            if (mainNotActiveUnit == null)
            {
                return;
            }

            if (ControlledObject != null)
            {
                ControlledObject.SetIntellect(null, false);
                ControlledObject.Destroying -= AlternativeUnitAllowPlayerControl_Destroying;
            }

            if (!mainNotActiveUnit.IsSetForDeletion)
            {
                mainNotActiveUnit.Server_EnableSynchronizationPositionsToClients = true;

                mainNotActiveUnit.Position = mainNotActiveUnitRestorePosition;
                //find free position for movable player controlled units
                if (ControlledObject != null)
                {
                    //Tank, Car specific
                    if (ControlledObject is Tank || ControlledObject is Car)
                    {
                        mainNotActiveUnit.Position = FindFreePositionForUnit(
                            mainNotActiveUnit, ControlledObject.Position);
                    }
                }

                mainNotActiveUnit.OldPosition = mainNotActiveUnit.Position;

                mainNotActiveUnit.Visible = true;

                UnsubscribeToDeletionEvent(mainNotActiveUnit);

                //restore contact groups for shapes
                if (mainNotActiveUnitShapeContactGroups != null)
                {
                    foreach (Body body in mainNotActiveUnit.PhysicsModel.Bodies)
                    {
                        foreach (Shape shape in body.Shapes)
                        {
                            int group;
                            if (mainNotActiveUnitShapeContactGroups.TryGetValue(shape, out group))
                            {
                                shape.ContactGroup = group;
                            }
                        }
                    }
                    mainNotActiveUnitShapeContactGroups.Clear();
                    mainNotActiveUnitShapeContactGroups = null;
                }

                mainNotActiveUnit.SetIntellect(this, false);

                ControlledObject = mainNotActiveUnit;
            }
            else
            {
                ControlledObject = null;
            }

            mainNotActiveUnit = null;

            //send mainNotActiveUnit to clients
            if (EntitySystemWorld.Instance.IsServer())
            {
                Server_SendMainNotActiveUnitToClients(EntitySystemWorld.Instance.RemoteEntityWorlds);
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        private void ServerOrSingle_ChangeMainControlledUnit(Unit unit)
        {
            //Change player controlled unit
            mainNotActiveUnit = ControlledObject;

            //send mainNotActiveUnit to clients
            if (EntitySystemWorld.Instance.IsServer())
                Server_SendMainNotActiveUnitToClients(EntitySystemWorld.Instance.RemoteEntityWorlds);

            if (mainNotActiveUnit != null)
            {
                SubscribeToDeletionEvent(mainNotActiveUnit);

                mainNotActiveUnit.SetIntellect(null, false);
                mainNotActiveUnitRestorePosition = mainNotActiveUnit.Position;

                //disable collision for shapes and save contact groups
                mainNotActiveUnitShapeContactGroups = new Dictionary<Shape, int>();
                foreach (Body body in mainNotActiveUnit.PhysicsModel.Bodies)
                {
                    foreach (Shape shape in body.Shapes)
                    {
                        mainNotActiveUnitShapeContactGroups.Add(shape, shape.ContactGroup);
                        shape.ContactGroup = (int)ContactGroup.NoContact;
                    }
                }

                mainNotActiveUnit.Server_EnableSynchronizationPositionsToClients = false;

                ControlledObject = unit;
                unit.SetIntellect(this, false);

                if (GameMap.Instance.GameType == GameMap.GameTypes.AssaultKnights)
                    unit.InitialFaction = mainNotActiveUnit.InitialFaction;
                unit.Destroying += AlternativeUnitAllowPlayerControl_Destroying;
            }
        }