Exemplo n.º 1
0
    public void Fire(ServerPlayer player, FireInfo info)
    {
        GameObject projObj = (GameObject)Network.Instantiate(weaponPrefab, info.origin, Quaternion.identity, 2);
        projObj.GetComponent<Projectile>().Init(player, this, info);

        fireTimer = fireRate;
        ammo--;
    }
Exemplo n.º 2
0
        private bool Fire(ControlInfo fireInfo)
        {
            using (FireInfo shootInfo = ShootTrigger(_WeaponContainer, fireInfo.Down, fireInfo.Stay))
            {
                _Animator.SetBool(FIRE, shootInfo.HasShot);

                if (shootInfo.HasShot)
                {
                    PublicEvents.GunFire?.Invoke();
                    _Recoil.Next();
                }

                return(shootInfo.FireCheckPass &&
                       shootInfo.BurstRequirePass &&
                       shootInfo.IntervalPass &&
                       shootInfo.SafetyPass &&
                       !shootInfo.AmmoPass &&
                       fireInfo.Down);
            }
        }
Exemplo n.º 3
0
    public virtual void Init(ServerPlayer player, WeaponInfo weapon, FireInfo info)
    {
        owner = player.GetOwner();
        direction = info.direction;
        GetComponent<Rigidbody2D>().AddForce(direction * GetPower(weapon), ForceMode2D.Impulse);

        long projID = ProjectileManager.Inst.GetUniqueKeyForNewProjectile();
        ProjectileManager.Inst.Set(projID, this);

        Physics2D.IgnoreCollision(collider, player.GetComponent<Collider2D>());

        OnInit();
        BroadcastInit();
    }
Exemplo n.º 4
0
    public void Fire(byte[] fireData, NetworkMessageInfo msgInfo)
    {
        if (!Network.isServer) return;
            //if (!PlayerManager.Inst.IsValidPlayer(player.GetOwner(), msgInfo.sender)) return;

            C2S.Fire fire = new C2S.Fire();
            fire.DeserializeFromBytes(fireData);

            if (!CanFire(fire.weaponType)) return;

            lock (weaponLock)
            {
                ChangeWeapon(fire.weaponType);

                WeaponInfo weapon = weapons[fire.weaponType];

                FireInfo info = new FireInfo(player.GetOwner(), player.transform.position, fire.direction);

                weapon.Fire(player, info);
            }
    }
Exemplo n.º 5
0
    public static void Connect(int lobbyId)
    {
        joinLobby = false;
        ws        = new WebSocket(uri);
        List <string> log = new List <string>();

        ws.OnMessage += (senders, d) =>
        {
            try
            {
                WSResponse res;
                res = JsonConvert.DeserializeObject <WSResponse>(d.Data.ToString());
                //Console.Title = res.identifier;

                if (res.identifier == "order")
                {
                    //Console.Title = "Recieved order";
                    if (res.msg == "reload")
                    {
                        getLobby = true;
                    }
                    if (res.msg == "start")
                    {
                        Terminal.WriteLine("Received start order");
                        start = true;
                        //Console.Title = "Starting game!";
                    }
                }

                if (res.identifier == "setUserId")
                {
                    if (res.type == "txt")
                    {
                        Lobby.user.userId = int.Parse(res.msg);
                    }
                }

                if (res.identifier == "update")
                {
                    try
                    {
                        GameInfo gameInfo = JsonConvert.DeserializeObject <GameInfo>(res.msg);
                        //File.WriteAllLines("res.json", new string[] { JsonConvert.SerializeObject(gameInfo) });

                        players = gameInfo.players;
                        if (playerCount != players.Count)
                        {
                            placePlayers = true;
                        }
                        playerCount = players.Count;

                        map    = gameInfo.mapIndex;
                        update = true;
                    }
                    catch (System.Exception ex)
                    {
                        Terminal.WriteLine(ex.Message);
                    }
                }

                if (res.identifier == "fireResponse")
                {
                    FireResponse fireResponse = JsonConvert.DeserializeObject <FireResponse>(res.msg);
                    Terminal.WriteLine("Fireresponse: Status: " + fireResponse.status + ", msg: " + fireResponse.msg);
                }

                if (res.identifier == "fireInfo")
                {
                    Terminal.WriteLine("Received bullet info - " + res.msg);
                    try
                    {
                        FireInfo _fireInfo = JsonConvert.DeserializeObject <FireInfo>(res.msg);
                        fireInfo = _fireInfo;
                        fired    = true;
                    }
                    catch (System.Exception ex)
                    {
                        Terminal.WriteLine(ex.Message);
                    }
                }

                if (res.identifier == "joinResponse")
                {
                    JoinRequestResponse joinRequestResponse = JsonConvert.DeserializeObject <JoinRequestResponse>(res.msg);

                    if (joinRequestResponse.status == "success")
                    {
                        joinLobby = true;
                        joinId    = lobbyId;
                    }
                    else
                    {
                        display        = true;
                        displayMessage = joinRequestResponse.msg;
                        displayTitle   = joinRequestResponse.status;
                    }
                }

                if (res.identifier == "promoteResponse")
                {
                    PromoteRequestResponse promoteRequestResponse = JsonConvert.DeserializeObject <PromoteRequestResponse>(res.msg);

                    //Console.Title = (kickRequestResponse.msg);
                    if (promoteRequestResponse.status == "success")
                    {
                    }
                    else
                    {
                        display        = true;
                        displayMessage = promoteRequestResponse.msg;
                        displayTitle   = promoteRequestResponse.status;
                    }
                }
                if (res.identifier == "swapTeamResponse")
                {
                    SwapTeamRequestResponse swapTeamRequestResponse = JsonConvert.DeserializeObject <SwapTeamRequestResponse>(res.msg);

                    //Console.Title = (kickRequestResponse.msg);
                    if (swapTeamRequestResponse.status == "success")
                    {
                    }
                    else
                    {
                        display        = true;
                        displayMessage = swapTeamRequestResponse.msg;
                        displayTitle   = swapTeamRequestResponse.status;
                    }
                }
                if (res.identifier == "kickResponse")
                {
                    KickRequestResponse kickRequestResponse = JsonConvert.DeserializeObject <KickRequestResponse>(res.msg);

                    //Console.Title = (kickRequestResponse.msg);

                    if (kickRequestResponse.status == "success")
                    {
                        if (int.Parse(kickRequestResponse.msg) == Lobby.user.userId)
                        {
                            Disconnect();
                            kicked         = true;
                            display        = true;
                            displayTitle   = "Oops";
                            displayMessage = "You were kicked";
                        }
                    }
                }
                if (res.identifier == "startResponse")
                {
                    StartRequestResponse startRequestResponse = JsonConvert.DeserializeObject <StartRequestResponse>(res.msg);

                    //Console.Title = (kickRequestResponse.msg);

                    if (startRequestResponse.status == "success")
                    {
                    }
                    else
                    {
                        display        = true;
                        displayMessage = startRequestResponse.msg;
                        displayTitle   = startRequestResponse.status;
                    }
                }

                if (res.identifier == "displayUpdateResponse")
                {
                    UpdataDisplayInfoResponse updataDisplayInfoResponse = JsonConvert.DeserializeObject <UpdataDisplayInfoResponse>(res.msg);

                    if (updataDisplayInfoResponse.status == "success")
                    {
                        //Console.Title = "I666 - Updated display info";
                    }
                }

                if (res.identifier == "positionUpdateResponse")
                {
                    PositionUpdateResponse updataDisplayInfoResponse = JsonConvert.DeserializeObject <PositionUpdateResponse>(res.msg);

                    //Console.Title = (kickRequestResponse.msg);
                    if (updataDisplayInfoResponse.status == "success")
                    {
                    }
                    else
                    {
                        Console.Title = updataDisplayInfoResponse.msg;
                    }
                }

                if (res.identifier == "pingResponse")
                {
                    Lobby.user.ping = (int)stopWatch.ElapsedMilliseconds;
                    Lobby.DisplayUpdate();
                    stopWatch.Stop();
                    stopWatch.Reset();
                    getLobby = true;
                    //Console.Title = "I666 : " + Lobby.user.ping;
                }

                log.Add("Received message -  " + d.Data.ToString() + " " + senders.ToString());
                //File.WriteAllLines("res.json", log.ToArray());
            }
            catch (System.Exception ex)
            {
                Terminal.WriteLine(ex.Message);
                //File.WriteAllLines("res.json", new string[] { "Something went wrong - " + ex.Message + ", " + d.Data.ToString() });
            }
        };

        ws.OnClose += (senders, d) =>
        {
            Terminal.WriteLine("Closed connection");
            log.Add("Connection closed - " + d.ToString() + " " + senders.ToString());
            //File.WriteAllLines("res.json", log.ToArray());

            return;
        };

        ws.Connect();
        Lobby.Join(lobbyId);
    }