public void WeaponFiring(Packet packet)
    {
        Message_WeaponFiring message = ((PacketSingle)packet).message as Message_WeaponFiring;

        if (message.UID != networkUID)
        {
            return;
        }
        //To switch weapon, we go back one previous one on the index and then toggle it to go forward one.
        //So that everything gets called which is in the normal game.
        List <string> uniqueWeapons = traverse.Field("uniqueWeapons").GetValue() as List <string>;

        traverse.Field("weaponIdx").SetValue((message.weaponIdx - 1) % uniqueWeapons.Count);
        weaponManager.CycleActiveWeapons(); //Should move it one forward to the same weapon
        weaponManager.SetMasterArmed(true);
        weaponManager.StartFire();
    }
Exemplo n.º 2
0
    private void Awake()
    {
        lastMessage              = new Message_PlaneUpdate(false, 0, 0, 0, 0, 0, 0, false, false, networkUID);
        lastFiringMessage        = new Message_WeaponFiring(-1, networkUID);
        lastStoppedFiringMessage = new Message_WeaponStoppedFiring(networkUID);


        wheelsController = GetComponent <WheelsController>();
        aeroController   = GetComponent <AeroController>();
        vRThrottle       = gameObject.GetComponentInChildren <VRThrottle>();
        if (vRThrottle == null)
        {
            Debug.Log("Cound't find throttle");
        }
        else
        {
            vRThrottle.OnSetThrottle.AddListener(SetThrottle);
        }

        weaponManager = GetComponent <WeaponManager>();
        if (weaponManager == null)
        {
            Debug.LogError("Weapon Manager was null on our vehicle");
        }
        cmManager = GetComponentInChildren <CountermeasureManager>();
        if (cmManager == null)
        {
            Debug.LogError("CountermeasureManager was null on our vehicle");
        }
        fuelTank = GetComponent <FuelTank>();
        if (fuelTank == null)
        {
            Debug.LogError("FuelTank was null on our vehicle");
        }

        Networker.WeaponSet += WeaponSet;

        traverse = Traverse.Create(weaponManager);
        Debug.Log("Done Plane Sender");
    }
Exemplo n.º 3
0
    private void Awake()
    {
        actor             = gameObject.GetComponent <Actor>();
        lastFiringMessage = new Message_WeaponFiring(-1, false, false, networkUID);
        // lastStoppedFiringMessage = new Message_WeaponStoppedFiring(networkUID);
        lastCountermeasureMessage = new Message_FireCountermeasure(true, true, networkUID);
        lastDeathMessage          = new Message_Death(networkUID, false);
        wheelsController          = GetComponent <WheelsController>();
        aeroController            = GetComponent <AeroController>();
        isPlayer       = actor.isPlayer;
        sequenceNumber = 0;
        lastMessage    = new Message_PlaneUpdate(false, 0, 0, 0, 0, 0, 0, false, false, false, networkUID, sequenceNumber);

        engine = gameObject.GetComponentInChildren <ModuleEngine>();
        if (engine == null)
        {
            Debug.Log("engine was null on vehicle " + gameObject.name);
        }

        weaponManager = GetComponent <WeaponManager>();
        if (weaponManager == null)
        {
            Debug.LogError("Weapon Manager was null on vehicle " + gameObject.name);
        }
        else
        {
            traverse             = Traverse.Create(weaponManager);
            Networker.WeaponSet += WeaponSet;
            //weaponManager.OnWeaponEquipped += Rearm;
            //weaponManager.OnWeaponUnequippedHPIdx +=Rearm;

            //detect player rearm
            PlayerVehicleSetup pv = gameObject.GetComponent <PlayerVehicleSetup>();
            if (pv != null)
            {
                pv.OnEndRearming.AddListener(Rearm);
            }

            if (actor.isPlayer && weaponManager.GetIWBForEquip(3) != null)
            {
                iwb = weaponManager.GetIWBForEquip(3);
            }
        }

        cmManager = GetComponentInChildren <CountermeasureManager>();
        if (cmManager == null)
        {
            Debug.LogError("CountermeasureManager was null on vehicle " + gameObject.name);
        }
        else
        {
            cmManager.OnFiredCM += FireCountermeasure;
        }

        fuelTank = GetComponent <FuelTank>();
        if (fuelTank == null)
        {
            Debug.LogError("FuelTank was null on vehicle " + gameObject.name);
        }


        Debug.Log("Done Plane Sender");
        tailhook   = GetComponentInChildren <Tailhook>();
        launchBar  = GetComponentInChildren <CatapultHook>();
        refuelPort = GetComponentInChildren <RefuelPort>();
    }
    public void WeaponFiring(Packet packet)
    {
        Message_WeaponFiring message = ((PacketSingle)packet).message as Message_WeaponFiring;

        if (message.UID != networkUID)
        {
            return;
        }

        if (weaponManager.isMasterArmed == false)
        {
            weaponManager.ToggleMasterArmed();
        }
        idx = (int)traverse.Field("weaponIdx").GetValue();

        /*while (message.weaponIdx != idx && i < 60)
         * {
         *  if (weaponManager.isMasterArmed == false)
         *  {
         *      weaponManager.ToggleMasterArmed();
         *  }
         *  // Debug.Log(idx + " " + message.weaponIdx);
         *  i++;
         * }
         * if (i > 59)
         * {
         *  Debug.Log("couldn't change weapon idx to right weapon for aircraft " + gameObject.name);
         * }*/
        weaponManager.SetWeapon(message.weaponIdx);
        idx = (int)traverse.Field("weaponIdx").GetValue();
        if (idx != message.weaponIdx)
        {
            Debug.LogWarning("Couldn't change weapon idx to the right weapon for aircraft " + gameObject.name);
        }
        if (message.isFiring != weaponManager.isFiring)
        {
            if (message.isFiring)
            {
                if (weaponManager.currentEquip is HPEquipMissileLauncher)
                {
                    lastml = weaponManager.currentEquip as HPEquipMissileLauncher;
                    //Traverse.Create(lastml.ml).Field("missileIdx").SetValue(message.missileIdx);
                    Debug.Log("Single firing this missile " + weaponManager.currentEquip.shortName);
                    //weaponManager.SingleFire();
                }
                else if (weaponManager.currentEquip is RocketLauncher)
                {
                    weaponManager.SingleFire();
                }
                else
                {
                    Debug.Log("try start fire for vehicle" + gameObject.name + " on current equip " + weaponManager.currentEquip);
                    if (message.noAmmo && noAmmo == false)
                    {
                        if (weaponManager.currentEquip is HPEquipGun)
                        {
                            ((HPEquipGun)weaponManager.currentEquip).gun.currentAmmo = 0;
                            noAmmo = true;
                        }
                        else if (weaponManager.currentEquip is HPEquipGunTurret)
                        {
                            ((HPEquipGunTurret)weaponManager.currentEquip).gun.currentAmmo = 0;
                            noAmmo = true;
                        }
                    }
                    else
                    {
                        if (weaponManager.currentEquip is HPEquipGun)
                        {
                            ((HPEquipGun)weaponManager.currentEquip).gun.currentAmmo = ((HPEquipGun)weaponManager.currentEquip).gun.maxAmmo;
                            noAmmo = false;
                        }
                        else if (weaponManager.currentEquip is HPEquipGunTurret)
                        {
                            ((HPEquipGun)weaponManager.currentEquip).gun.currentAmmo = ((HPEquipGun)weaponManager.currentEquip).gun.maxAmmo;
                            noAmmo = false;
                        }
                    }
                    weaponManager.StartFire();
                }
            }
            else
            {
                if (!(weaponManager.currentEquip is HPEquipMissileLauncher || weaponManager.currentEquip is RocketLauncher))
                {
                    weaponManager.EndFire();
                }
            }
        }
    }