예제 #1
0
    private void StartNewGame()
    {
        isMainMenu = false;
        //  Explicitly create player
        Gun glock17 = new Gun("Glock 17", "9mm", 100, 20, 15, 7, 17);
        Gun m4a1    = new Gun("M4A1", "5.56mm", 100, 50, 25, 20, 30);

        PlayerBoat = new Boat(0, 0, "Player Boat", HealthBarPrefab);
        PlayerBoat.addNewSlot(0, 0, 1, "Gun Slot");
        Slot slotRef;

        PlayerBoat.getSlot(0, 0, 1, out slotRef);
        GunSlot gunSlotRef = slotRef as GunSlot;

        gunSlotRef.upgradeSlot();
        gunSlotRef.addGun(m4a1);
        gunSlotRef.addGun(m4a1);
        //  Explicitly create enemy
        BoatsInWorld.Add(PlayerBoat);
        PlayerBoat.Draw();
        BoatsInWorld.Add(new Boat(20, 10, "Enemy Boat", HealthBarPrefab));
        //  Prepare the scene
        WaterScenery.SetActive(true);
        if (!CameraControl.FollowBoat(ref PlayerBoat))
        {
            Debug.Log("Camera couldn't follow the player.");
        }
    }
예제 #2
0
        //todo -- this needs to fleshed out more once weapons work.
        //probably dont want an object for each point. Probably want
        //to add a gunslot component here to contain this data instead.
        private GameObject CreateGunPoints()
        {
            if (!model.HasGunSlots)
            {
                return(null);
            }
            GameObject     retn     = new GameObject("Gun Points");
            List <GunSlot> gunSlots = model.gunSlots;

            for (int i = 0; i < gunSlots.Count; i++)
            {
                GunSlot slot = gunSlots[i];

                for (int j = 0; j < slot.gunPoints.Length; j++)
                {
                    GameObject     go       = new GameObject("Gun Point " + i + " -- " + j);
                    PositionNormal gunPoint = slot.gunPoints[j];
                    go.transform.parent   = retn.transform;
                    go.transform.position = gunPoint.point;
                    if (gunPoint.normal == Vector3.zero)
                    {
                        gunPoint.normal = Vector3.forward;
                    }
                    go.transform.rotation = Quaternion.LookRotation(gunPoint.normal, Vector3.up);
                }
            }

            return(retn);
        }
예제 #3
0
        public GunSlot[] GetUserGuns(string name, Ship s)
        {
            GunSlot[] gs     = null;
            byte      gunNum = 0;

            try
            {
                reader = XmlReader.Create("world\\players\\" + name + ".xml");
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        switch (reader.Name)
                        {
                        case "Count":
                        {
                            reader.Read();
                            gs = new GunSlot[int.Parse(reader.Value)];
                        }
                        break;

                        case "GunType":
                        {
                            reader.Read();
                            GunType gt = (GunType)byte.Parse(reader.Value);
                            gs[gunNum] = new GunSlot(gt, s);
                            gunNum++;
                        }
                        break;
                        }
                    }
                }
                reader.Close();
                return(gs);
            }
            catch
            {
                if (reader != null)
                {
                    reader.Close();
                }
                return(null);
            }
        }
예제 #4
0
    private void CreateNewPlayerShip(NetIncomingMessage incmsg)
    {
        net.SetLogging(false);
        string   name = incmsg.ReadString();
        Vector2  pos = new Vector2(incmsg.ReadSingle(), incmsg.ReadSingle());
        int      xpos = incmsg.ReadInt32(), ypos = incmsg.ReadInt32();
        bool     isRefreshing = false;
        ShipType st           = (ShipType)incmsg.ReadByte();
        Faction  f            = (Faction)incmsg.ReadByte();

        for (int i1 = 0; i1 < world.ships.Count; i1++)
        {
            if (world.ships[i1].shipName != null && world.ships[i1].shipName.Equals(name))
            {
                isRefreshing = true;
            }
        }
        if (!isRefreshing)
        {
            int[]      components = { incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte() };
            ShipPlayer s          = new ShipPlayer(pos, pos, f, st, components, world, 0, 0);
            s.shipName = name;
            if (name.Equals(core.GetPlayerName()))
            {
                core.SetCameraTarget(s.Position);
            }
            s.jumpX = xpos;
            s.jumpY = ypos;
            int       gunNum = incmsg.ReadByte();
            GunSlot[] gs     = new GunSlot[gunNum];
            for (int i = 0; i < gunNum; i++)
            {
                gs[i] = new GunSlot((GunType)incmsg.ReadByte(), s);
            }
            s.AddGuns(gs);
            world.ships.Add(s);
            Core.console.AddDebugString(name + " connected");
        }
    }
예제 #5
0
    private void CreatePlayerShip(NetIncomingMessage incmsg)
    {
        string   name         = incmsg.ReadString();
        Vector2  pos          = new Vector2(incmsg.ReadSingle(), incmsg.ReadSingle());
        float    rot          = incmsg.ReadSingle();
        bool     isRefreshing = false;
        ShipType st           = (ShipType)incmsg.ReadByte();
        Faction  f            = (Faction)incmsg.ReadByte();

        for (int i1 = 0; i1 < world.ships.Count; i1++)
        {
            if (world.ships[i1].shipName != null && world.ships[i1].shipName.Equals(name))
            {
                isRefreshing = true;
                break;
            }
        }
        if (!isRefreshing)
        {
            int[]      components = { incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte() };
            ShipPlayer s          = new ShipPlayer(pos, pos, f, st, components, world, 0, 0);
            s.shipName = name;
            if (name.Equals(core.GetPlayerName()))
            {
                core.cam.camToNewPos = true;
                core.cam.newCamPos   = s.Position;
            }
            s.Rotation  = rot;
            s.isJumping = false;
            int       gunNum = incmsg.ReadByte();
            GunSlot[] gs     = new GunSlot[gunNum];
            for (int i = 0; i < gunNum; i++)
            {
                gs[i] = new GunSlot((GunType)incmsg.ReadByte(), s);
            }
            s.AddGuns(gs);
            world.ships.Add(s);
        }
    }
예제 #6
0
    void FindGunSlotAndPlayer()
    {
        Transform parent = transform.parent;

        if (parent == null)
        {
            enabled = false;
            return;
        }

        GunSlot weaponSlot = parent.GetComponent <GunSlot>();

        if (weaponSlot != null)
        {
            this.gunSlot = weaponSlot;

            Player player = weaponSlot.Player;

            if (player != null)
            {
                this.player = player;
            }
        }
    }
예제 #7
0
    private void CreateNpcShip(NetIncomingMessage incmsg, bool b)
    {
        if (b)
        {
            string name         = null;
            int    id           = incmsg.ReadInt32();
            bool   isRefreshing = false;
            for (int i1 = 0; i1 < world.ships.Count; i1++)
            {
                if (world.ships[i1].id == id)
                {
                    isRefreshing = true;
                }
            }
            if (!isRefreshing)
            {
                Vector2  pos = new Vector2(incmsg.ReadSingle(), incmsg.ReadSingle());
                int      xpos = incmsg.ReadInt32(), ypos = incmsg.ReadInt32();
                ShipType st = (ShipType)incmsg.ReadByte();
                Faction  f  = (Faction)incmsg.ReadByte();
                switch (f)
                {
                case Faction.Civilian:
                    name = "<Bot> Engi";
                    break;

                case Faction.Enemy:
                    name = "<Bot> Saimon";
                    break;

                case Faction.Human:
                    name = "<Bot> Human";
                    break;
                }

                int[]   components = { incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte() };
                ShipNPC s          = new ShipNPC(pos, pos, f, st, components, world, 0, 0);
                s.shipName = name;
                s.id       = id;
                s.jumpX    = xpos;
                s.jumpY    = ypos;
                int       gunNum = incmsg.ReadByte();
                GunSlot[] gs     = new GunSlot[gunNum];
                for (int i = 0; i < gunNum; i++)
                {
                    gs[i] = new GunSlot((GunType)incmsg.ReadByte(), s);
                }
                s.AddGuns(gs);
                world.shipsNpc.Add(s);
            }
        }
        else
        {
            string name         = null;
            int    id           = incmsg.ReadInt32();
            bool   isRefreshing = false;
            for (int i1 = 0; i1 < world.ships.Count; i1++)
            {
                if (world.ships[i1].id == id)
                {
                    isRefreshing = true;
                }
            }
            if (!isRefreshing)
            {
                Vector2  pos = new Vector2(incmsg.ReadSingle(), incmsg.ReadSingle());
                float    rot = incmsg.ReadSingle();
                ShipType st  = (ShipType)incmsg.ReadByte();
                Faction  f   = (Faction)incmsg.ReadByte();
                switch (f)
                {
                case Faction.Civilian:
                    name = "<Bot> Engi";
                    break;

                case Faction.Enemy:
                    name = "<Bot> Saimon";
                    break;

                case Faction.Human:
                    name = "<Bot> Human";
                    break;
                }

                int[]   components = { incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte(), incmsg.ReadByte() };
                ShipNPC s          = new ShipNPC(pos, pos, f, st, components, world, 0, 0);
                s.shipName  = name;
                s.id        = id;
                s.isJumping = false;
                int       gunNum = incmsg.ReadByte();
                GunSlot[] gs     = new GunSlot[gunNum];
                for (int i = 0; i < gunNum; i++)
                {
                    gs[i] = new GunSlot((GunType)incmsg.ReadByte(), s);
                }
                s.AddGuns(gs);
                world.shipsNpc.Add(s);
            }
        }
    }
예제 #8
0
    private void ConfrimSelect(NetIncomingMessage incmsg)
    {
        string      playerName = incmsg.ReadString();
        World       w          = serverCore.GetWorld();
        DataBase    db         = serverCore.GetDataBase();
        ConfrimType ct         = (ConfrimType)incmsg.ReadByte();
        int         xpos       = serverCore.random.Next(2) == 0 ? 750 : -750;
        int         ypos       = serverCore.random.Next(2) == 0 ? 750 : -750;

        if (ct == ConfrimType.SelectFaction)
        {
            Faction   f          = (Faction)incmsg.ReadByte();
            ShipType  st         = 0;
            Vector2   pos        = Vector2.Zero;
            GunSlot[] gs         = new GunSlot[2];
            int[]     components = { 1, 1, 0, 0, 0, 0, 0 };
            if (f == Faction.Civilian)
            {
                st  = ShipType.CivSmall1;
                pos = new Vector2(1500, -500);
            }
            else if (f == Faction.Enemy)
            {
                st  = ShipType.EnemySmall1;
                pos = new Vector2(-1500, -500);
            }
            else if (f == Faction.Human)
            {
                st  = ShipType.HumanSmall1;
                pos = new Vector2(0, 1500);
            }
            ShipPlayer s = new ShipPlayer(pos, pos, f, st, components, w, 0, 0);
            s.shipName = playerName;
            if (f == Faction.Civilian)
            {
                for (int i = 0; i < 2; i++)
                {
                    gs[i] = new GunSlot(GunType.GausSmall, s);
                }
            }
            else if (f == Faction.Enemy)
            {
                for (int i = 0; i < 2; i++)
                {
                    gs[i] = new GunSlot(GunType.LaserSmall, s);
                }
            }
            else if (f == Faction.Human)
            {
                for (int i = 0; i < 2; i++)
                {
                    gs[i] = new GunSlot(GunType.PlasmSmall, s);
                }
            }
            s.jumpX = xpos;
            s.jumpY = ypos;
            s.AddGuns(gs);
            //timersToSendNpcs.Add(0);
            //netConnections.Add(incmsg.SenderConnection);
            ServerPacketSender.SendAllNpcs(w, incmsg.SenderConnection);
            w.ships.Add(s);
            ServerPacketSender.SendNewPlayer(s, false);
            ServerCore.LogAdd(playerName + " connected.");
            db.SaveUser(playerName, s);
        }
    }