예제 #1
0
    public void AddNetworkedProjectile(string name, string pID, Vector3 org, Vector3 vel, Vector3 rot, WEAPONTYPE weapon)
    {
        Projectile proj = _projectiles.Where(p => p.Name.Replace("@", "") == name).SingleOrDefault();

        if (proj == null)
        {
            Peer p = _game.Network.PeerList.Where(e => e.ID == Convert.ToInt64(pID)).SingleOrDefault();
            if (p != null)
            {
                ProjectileInfo.PROJECTILE projType = ProjectileInfo.Weapons[weapon];
                proj      = (Projectile)ProjectileScenes[projType].Instance();
                proj.Name = name;
                _projectiles.Add(proj);
                this.AddChild(proj);
                float ping = IsNetworkMaster() ? 0 : p.Ping;
                proj.Init(p.Player, vel, weapon, _game);
            }
            else
            {
                return;
            }
        }
        else // apply update to existing projectile
        {
            proj.SetServerState(org, vel, rot);
            Transform t = proj.GlobalTransform;

            t.origin             = org;
            proj.GlobalTransform = t;
            proj.Rotation        = rot;
            proj.Velocity        = vel;
        }
    }
예제 #2
0
    // when a player attacks
    public Projectile AddProjectile(Player shooter, Vector3 dest, string projName, WEAPONTYPE weapon)
    {
        ProjectileInfo.PROJECTILE projType = ProjectileInfo.Weapons[weapon];
        Projectile proj = (Projectile)ProjectileScenes[projType].Instance();

        this.AddChild(proj);
        _projectiles.Add(proj);

        Peer  p    = _game.Network.PeerList.Where(e => e.ID == shooter.ID).SingleOrDefault();
        float ping = 0f;

        if (p != null)
        {
            ping = IsNetworkMaster() ? p.Ping : 0f;
        }

        proj.Init(shooter, dest.Normalized(), weapon, _game);
        proj.Velocity *= proj.Speed;
        if (proj is HandGrenade h)
        {
            h.Visible           = false;
            shooter.PrimingGren = h;
        }
        proj.Name = projName.Replace("\"", "").Length > 0 ? projName : shooter.ID + "!" + proj.Name;

        // godot inserts @ signs and numbers to non unique names that can happen due to sync issues
        // it also currently doesn't allow you to manually insert them, so server sets wrong name! and sends back wrong name!
        // great architecture!

        // if this is too slow we need to track unique projectile count on client and set that as name, but i worry about uniqueness still
        proj.Name = proj.Name.Replace("@", "");

        return(proj);
    }