Пример #1
0
    private void tryChangeTarget()
    {
        if (rootFlow.isHostInstance)
        {
            changeCycleCounter -= Time.deltaTime;
            if (changeCycleCounter < 0)
            {
                changeCycleCounter = changeCycleCounterMax;

                CombatFlow targetFlow = findNearestTarget();
                if (targetFlow != null && targetFlow.GetComponent <Rigidbody>() != targetRb)
                {
                    //Debug.LogWarning
                    //Debug.LogWarning("new target name: " + targetFlow.name);
                    if (targetRb != null && targetFlow != null)
                    {
                        Debug.LogWarning("AAA found new target. Old: " + targetRb.gameObject.name + ", new: " + targetFlow.gameObject.name);
                    }

                    turretNet.setTarget(targetFlow);

                    // only target's instance will deal damage. Rest will be cosmetic-only
                    rootFlow.giveOwnership(targetFlow.photonView.ViewID);
                }
            }
        }
    }
Пример #2
0
 private void setRefs()
 {
     myCombatFlow = GetComponent <CombatFlow>();
     radar        = GetComponent <Radar>();
     rbRef        = GetComponent <Rigidbody>();
     flightSound  = GetComponent <AudioSource>();
 }
Пример #3
0
    public void rpcContactProcess(Vector3 position, int otherId)
    {
        if (oneImpactVictim == null)
        {
            transform.position = position;

            GameObject other     = null;
            CombatFlow otherFlow = null;

            if (otherId != -1)
            {
                other     = PhotonNetwork.GetPhotonView(otherId).gameObject;
                otherFlow = other.gameObject.GetComponent <CombatFlow>();
            }

            if (other != null)
            {
                oneImpactVictim = other.transform.root.gameObject;
            }

            Debug.Log("Bomb collided");
            // die immediately on collision
            myCombatFlow.dealLocalDamage(myCombatFlow.getHP());

            if (otherFlow != null && myCombatFlow.localOwned)
            {
                otherFlow.dealDamage(impactDamage);
            }
        }
    }
    private void beginUpdateAllCreeps()
    {
        List <int>        idList       = new List <int>();        // ID list
        List <float>      hpList       = new List <float>();      // HP list
        List <int>        targetIdList = new List <int>();        // targetID list
        List <Vector3>    posList      = new List <Vector3>();    // position list
        List <Quaternion> rotList      = new List <Quaternion>(); // rotation list


        for (int i = 0; i < myLaneUnits.Count; i++)
        {
            CombatFlow currentUnit = myLaneUnits[i];

            if (currentUnit != null)
            {
                idList.Add(currentUnit.photonView.ViewID);
                hpList.Add(currentUnit.getHP());
                targetIdList.Add(currentUnit.GetComponent <CreepControl>().getTargetId());
                posList.Add(currentUnit.transform.position);
                rotList.Add(currentUnit.transform.rotation);
            }
        }

        photonView.RPC("rpcUpdateAllCreeps", RpcTarget.Others, idList.ToArray(), hpList.ToArray(),
                       targetIdList.ToArray(),
                       posList.ToArray(), rotList.ToArray());
    }
Пример #5
0
    private void rpcPingPlayer(int photonId)
    {
        PhotonView targetView = PhotonNetwork.GetPhotonView(photonId);

        if (targetView != null)
        {
            CombatFlow targetFlow = targetView.GetComponent <CombatFlow>();
            if (radar == null)
            {
                radar = GetComponent <Radar>();
            }

            // all instances will have target set
            //  - this allows us to pass around ownership, to give more accurate display of missile position
            targetID     = photonId;
            myTarget     = targetView.gameObject;
            guidedLaunch = true;
            setRefs();
            //init();


            //radar.radarOn = targetFlow.isLocalPlayer;
            radar.pingPlayer = targetFlow.isLocalPlayer;

            radar.radarOn = radar.pingPlayer || myCombatFlow.localOwned || targetFlow.localOwned;
        }
    }
Пример #6
0
    //protected PhotonView photonView;

    // call from fixedUpdate()
    // either countdown reposition timer
    public void checkLinecastCollision()
    {
        if (lineCastViaDistance)
        {
            // project line toward rear
            previousPos = transform.position - transform.forward * linecastDistance;
        }
        else
        {
            if (linecastCurrentTimer > 0)
            {
                linecastCurrentTimer -= Time.deltaTime;
            }
            else
            {
                previousPos          = transform.position;
                linecastCurrentTimer = lineCastBackTime;
            }
        }

        if (armed)
        {
            RaycastHit hitInfo      = new RaycastHit();
            short      terrainLayer = 1 << 10; // only check collisions with terrain
            if (Physics.Linecast(previousPos, transform.position,
                                 out hitInfo, terrainLayer))
            {
                Debug.DrawLine(transform.position, hitInfo.point, Color.green, 1.0f);

                // hitInfo.point is confirmed absolutely to be correct. transform isn't moving as it should.
                //  - explosion triggering before able to move?

                Debug.Log("*********************************************************************  linecast hit");
                transform.position = hitInfo.point;

                int        id           = -1;
                GameObject otherRootObj = hitInfo.collider.transform.root.gameObject;
                CombatFlow otherFlow    = otherRootObj.GetComponent <CombatFlow>();
                if (otherFlow != null)
                {
                    id = otherRootObj.GetComponent <PhotonView>().ViewID;
                }

                //if (explodeOnOther(otherRootObj))
                {
                    if (networkImpact)
                    {
                        photonView.RPC("rpcContactProcess", RpcTarget.AllBuffered, transform.position,
                                       id);
                    }
                    else // local impact
                    {
                        //Debug.LogError("MYERROR: linecast triggered");
                        //rpcContactProcess(transform.position, id);
                        impactLocal(transform.position, otherRootObj);
                    }
                }
            }
        }
    }
    public CombatFlow assignNewLeader()
    {
        CombatFlow leader       = null;
        float      farthestDist = 0;

        for (int i = 0; i < myLaneUnits.Count; i++)
        {
            CombatFlow unit = myLaneUnits[i];

            if (unit != null)
            {
                float dist = Vector3.Distance(unit.transform.position, transform.position);
                if (dist > farthestDist)
                {
                    farthestDist = dist;
                    leader       = unit;
                }
            }
        }

        myLeader = leader;
        generateFrontWaveList();

        return(leader);
    }
Пример #8
0
 //private WarningComputer warnComputer;
 void Awake()
 {
     myFlow           = GetComponent <CombatFlow>();
     myRb             = GetComponent <Rigidbody>();
     lockedBy         = new List <CombatFlow>();
     incomingMissiles = new List <CombatFlow>();
 }
Пример #9
0
    public void linkToRadarSource(Radar radar)
    {
        hasSet      = true;
        textID.text = radar.radarID;

        CombatFlow radarFlow = radar.GetComponent <CombatFlow>();

        sourceFlow = radarFlow;

        radarSource = radar;
        linkedObj   = radar.gameObject;

        if (radarFlow.type == CombatFlow.Type.PROJECTILE)
        {
            Debug.LogWarning("Linking projectile radar " + radar.gameObject.name);
            isMissile = true;
            iconCenter.transform.localPosition = new Vector3(0, UI_POSITION_Y_MISSILE, 0);
            makeRed();
        }

        if (radarFlow.type == CombatFlow.Type.AIRCRAFT)
        {
            iconCenter.transform.localPosition = new Vector3(0, UI_POSITION_Y_AIRCRAFT, 0);
        }

        if (radarFlow.GetComponent <SamNetworking>() != null)
        {
            isSam = true;
        }
    }
Пример #10
0
    public void rpcLockedBy(int sourceID)
    {
        //lockedByIDs.Add(sourceID);

        if (myFlow.isLocalPlayer || myFlow.localOwned || myFlow.aiControlled)
        {
            Debug.Log("rpc locked by");
            PhotonView view = PhotonNetwork.GetPhotonView(sourceID);
            if (view != null)
            {
                CombatFlow sourceFlow = view.GetComponent <CombatFlow>();

                if (sourceFlow.type == CombatFlow.Type.PROJECTILE)
                {
                    incomingMissiles.Add(sourceFlow);
                }
                else
                {
                    lockedBy.Add(sourceFlow);
                }

                if (myFlow.isLocalPlayer)
                {
                    Radar radarSource = view.GetComponent <Radar>();
                    radarSource.rwrIcon.beginLock();
                }
            }
        }
    }
Пример #11
0
    public void rpcEndLockedBy(int sourceID)
    {
        if (myFlow.isLocalPlayer || myFlow.localOwned || myFlow.aiControlled)
        {
            Debug.Log("rpc end locked by");
            PhotonView view = PhotonNetwork.GetPhotonView(sourceID);
            if (view != null)
            {
                CombatFlow sourceFlow = view.GetComponent <CombatFlow>();

                if (sourceFlow.type == CombatFlow.Type.PROJECTILE)
                {
                    incomingMissiles.Remove(sourceFlow);

                    if (sourceFlow == highestThreatMissile)
                    {
                        highestThreatMissile = null;
                    }
                }
                else
                {
                    lockedBy.Remove(sourceFlow);
                }

                if (myFlow.isLocalPlayer)
                {
                    Radar radarSource = view.GetComponent <Radar>();
                    radarSource.rwrIcon.endLock();
                }
            }
        }
    }
    public void rpcSetTankTurretTarget(int targetID)
    {
        PhotonView view = null;

        parentLane.ifCount++;
        if (targetID != -1)
        {
            view = PhotonNetwork.GetPhotonView(targetID);
        }

        parentLane.ifCount++;
        if (turret != null)
        {
            parentLane.ifCount++;
            if (view != null)
            {
                currentTarget = view.GetComponent <CombatFlow>();
                turret.target = view.gameObject;
            }
            else
            {
                currentTarget = null;
                turret.target = null;
            }
        }
    }
    private void findTarget()
    {
        if (turret != null)
        {
            // loop through lead wave of opponent lane
            List <CombatFlow> enemyLeadWave   = parentLane.opponentLM.frontWave;
            List <CombatFlow> possibleTargets = new List <CombatFlow>();

            for (int i = 0; i < enemyLeadWave.Count; i++)
            {
                CombatFlow currentFlow = enemyLeadWave[i];
                if (currentFlow != null)
                {
                    float dist = Vector3.Distance(currentFlow.transform.position, transform.position);
                    if (dist < effectiveRange)
                    {
                        possibleTargets.Add(currentFlow);
                    }
                }
            }

            if (possibleTargets.Count > 0)
            {
                int randIndex = Random.Range(0, possibleTargets.Count - 1);
                currentTarget = possibleTargets[randIndex];
                photonView.RPC("rpcSetTankTurretTarget", RpcTarget.All, currentTarget.photonView.ViewID);

                // Only execute this locally.
                //  Lane manager will pick this up, and call rpc to propogate to other clients
                //rpcSetTankTurretTarget(currentTarget.photonView.ViewID);
            }
        }
    }
    private bool enemyLeaderWithinRange()
    {
        CombatFlow enemyLeader = parentLane.opponentLM.getLeader();

        return(enemyLeader != null &&
               differenceFromSpawn(enemyLeader) < effectiveRange);
    }
Пример #15
0
 // Start is called before the first frame update
 void Start()
 {
     reticle = hudControl.mainHud.GetComponent <hudControl>().dropReticle;
     rb      = GetComponent <Rigidbody>();
     myFlow  = GetComponent <CombatFlow>();
     g       = Physics.gravity.magnitude;
 }
    private void refreshCreepArrays()
    {
        if (myLaneUnits.Count > creepDataArraySize)
        {
            creepDataArraySize = myLaneUnits.Count;

            creepIdArray     = new int[creepDataArraySize];
            creepTargetArray = new int[creepDataArraySize];
        }

        for (int i = 0; i < creepDataArraySize; i++)
        {
            if (i > (myLaneUnits.Count - 1))
            {
                creepIdArray[i] = -1;
            }
            else
            {
                CombatFlow currentFlow = myLaneUnits[i];

                if (currentFlow != null)
                {
                    CreepControl currentCreep = myLaneUnits[i].GetComponent <CreepControl>();
                    creepIdArray[i]     = currentCreep.photonView.ViewID;
                    creepTargetArray[i] = currentCreep.getTargetId();
                }
                else
                {
                    creepIdArray[i] = -1;
                }
            }
        }
    }
Пример #17
0
    public virtual bool explodeOnOther(GameObject other)
    {
        bool doAct = true; // various conditions will try to make this false

        CombatFlow otherFlow = null;

        if (other != null)
        {
            otherFlow = other.GetComponent <CombatFlow>();
        }

        // impact with effects
        if (other.CompareTag("Effects") && !impactOnEffects)
        {
            doAct = false;
        }


        if (otherFlow != null)
        {
            if (otherFlow.team == myTeam && !friendlyImpact)
            {
                doAct = false;
            }
        }
        return(doAct);
    }
Пример #18
0
    public void attack(CombatFlow target)
    {
        amOffensive();

        bool readyToFire    = readyToFireAt(target);
        bool tryLock        = tryLockTarget(target);
        bool hardpointReady = hardpoints.isReadyToFire();

        //Debug.Log("ReadyToFire: " + readyToFire + ", tryLock: " + tryLock + ", hardpointReady: " + hardpointReady);


        if (readyToFire && tryLock && hardpointReady)
        {
            Debug.Log("AI ready to fire");
            // do attack here
            rippleFireCounter = rippleFireDelay;
            GameObject launchedWeap = hardpoints.launchButtonDown();

            Debug.Log("======================== Launching weapon: " + launchedWeap);
            tryAddOutgoingWeap(launchedWeap);
        }
        else
        {
            // keep waiting until can do attack
            hardpoints.launchButtonUp();
        }
    }
Пример #19
0
    public void rpcSetOwnership(int photonID)
    {
        PhotonView view = PhotonNetwork.GetPhotonView(photonID);

        if (view != null)
        {
            CombatFlow player = view.GetComponent <CombatFlow>();
            localOwned = player.localOwned || player.isLocalPlayer;


            // This fixes bug where client launching against host-owned npc
            if (localOwned)
            {
                RealFlightControl flightCont = GetComponent <RealFlightControl>();
                if (flightCont != null)
                {
                    flightCont.enabled = true;
                }

                BasicMissile missile = GetComponent <BasicMissile>();
                if (missile != null)
                {
                    missile.setHasPassed(true);
                }
            }
        }
    }
Пример #20
0
    public CombatFlow findTarget(bool resetTargets = false)
    {
        CombatFlow prevTarget = activeTarget;

        //if (airTarget == null || maxMissilesOnTarget(airTarget) || !hasLineOfSight(airTarget) || resetTargets)
        //{

        //}

        airTarget = findAirTarget();

        if (gndTarget == null || maxMissilesOnTarget(gndTarget) || resetTargets)
        {
            gndTarget = findGroundTarget();
        }


        activeTarget = decideAirOrGroundTarget(airTarget, gndTarget);

        //Debug.Log("ActiveTarget: " + activeTarget + ", airTarget: " + airTarget + ", gndTarget: " + gndTarget);

        if (prevTarget != activeTarget)
        {
            rippleFireCounter = -1f; // don't bother waiting for ripple if selecting new target
            equipProperWeapon(activeTarget);
        }

        return(activeTarget);
    }
Пример #21
0
    public static float impactFuseVelocity = 100f; // impact incident velocity must be at least this value to explode

    // Start is called before the first frame update
    void Start()
    {
        pSystem                 = GetComponent <ParticleSystem>();
        myParticles             = new ParticleSystem.Particle[500];
        rootFlow                = transform.root.GetComponent <CombatFlow>();
        emitterForThisCollision = GetComponent <ParticleSystem>();
    }
Пример #22
0
    public bool hasLineOfSight(CombatFlow target)
    {
        int  terrainLayer = 1 << 10; // line only collides with terrain layer
        bool lineOfSight  = !Physics.Linecast(transform.position, target.transform.position, terrainLayer);

        return(lineOfSight);
    }
Пример #23
0
    public void rpcSetSamTarget(int viewID)
    {
        if (viewID != -1)
        {
            PhotonView view = PhotonNetwork.GetPhotonView(viewID);

            if (view != null)
            {
                CombatFlow targetFlow = view.GetComponent <CombatFlow>();

                sam.setTarget(targetFlow);

                Radar myRadar = GetComponent <Radar>();

                if (targetFlow.gameObject == GameManager.getGM().localPlayer)
                {
                    myRadar.rwrIcon.beginLock();
                }
                else
                {
                    myRadar.rwrIcon.endLock();
                }
            }
        }
        else
        {
            if (sam.currentTarget.gameObject == GameManager.getGM().localPlayer)
            {
                Radar myRadar = GetComponent <Radar>();
                myRadar.rwrIcon.endLock();
            }

            sam.setTarget(null);
        }
    }
Пример #24
0
    // only local owner should call this
    public void launchMissile(CombatFlow target)
    {
        if (myFlow.localOwned && target != null)
        {
            Debug.LogWarning("Launching at " + target.name);

            GameObject missileObj = PhotonNetwork.Instantiate(sam.missilePrefab.name,
                                                              sam.missileSpawnCenter.position, sam.missileSpawnCenter.rotation);

            BasicMissile missile     = missileObj.GetComponent <BasicMissile>();
            CombatFlow   missileFlow = missileObj.GetComponent <CombatFlow>();

            // this instance will network its position
            missileFlow.localOwned = true;
            missileFlow.isActive   = true;
            missile.myTarget       = target.gameObject;


            missile.myTeam   = transform.root.GetComponent <CombatFlow>().team;
            missileFlow.team = missile.myTeam;



            missile.launch();
            missile.radar.setRadarActive(true);
            //missile.radar.radarOn = true;
            photonView.RPC("rpcMissileInit", RpcTarget.AllBuffered, missile.photonView.ViewID);
        }
    }
Пример #25
0
    void rpcInitializeWeapon(int weaponId)
    {
        PhotonView pView = PhotonNetwork.GetPhotonView(weaponId);

        if (pView != null)
        {
            loadedWeaponObj = pView.gameObject;

            loadedWeaponObj.transform.position = spawnCenter.position;
            loadedWeaponObj.transform.rotation = spawnCenter.rotation;

            CombatFlow weaponFlow = loadedWeaponObj.GetComponent <CombatFlow>();
            Weapon     weapon     = loadedWeaponObj.GetComponent <Weapon>();

            weapon.myHardpoint = this;

            // locks weapon to hardpoint using fixedjoint
            weapon.linkToOwner(transform.root.gameObject);

            weapon.myTeam   = transform.root.GetComponent <CombatFlow>().team;
            weaponFlow.team = weapon.myTeam;
            //Debug.LogWarning("Setting weapon to player's team: " + transform.root.GetComponent<CombatFlow>().team);



            readyToFire = true;
        }
    }
Пример #26
0
    // theoretically, this should not be called unless collider is active
    private void explosionContactProcess(GameObject victim)
    {
        // deal damage
        // apply force


        GameObject targetRootObj = victim.transform.root.gameObject;

        //Debug.Log("Explosion contacted: " + victim.name + " with root: " + targetRootObj.name);

        // only act upon victim root if he is a new victim
        if (isNewVictim(targetRootObj))
        {
            explosionVictimRootList.Add(targetRootObj);


            Rigidbody  targetRb = targetRootObj.GetComponent <Rigidbody>();
            CombatFlow targetCF = targetRootObj.GetComponent <CombatFlow>();


            // whether or not explosion should act upon victim
            bool doAct = true; //various conditions will try to make this false


            //  if target has a CombatFlow
            if (targetCF != null)
            {
                // if target is friendly, and friendlyFire is disabled
                if (targetCF.team == team && !friendlyFire)
                {
                    doAct = false;
                }

                // if target is a Projectile, and
                if (targetCF.type == CombatFlow.Type.PROJECTILE && !damageProjectiles)
                {
                    doAct = false;
                }
            }


            //  if explosion will act upon target
            if (doAct)
            {
                // if target has a rigidBody, add explosive force
                if (targetRb != null)
                {
                    targetRb.AddExplosionForce(explosiveForce, transform.position, radius);
                }

                if (targetCF != null && coreDamage > 0)
                {
                    //Debug.Log("Explosion acting upon victim: " + targetRootObj + " for " + coreDamage + " damage, list count: " + explosionVictimRootList.Count);
                    //targetCF.currentHP -= coreDamage;
                    targetCF.dealDamage(coreDamage);
                }
            }
        }
    }
Пример #27
0
 void Awake()
 {
     pm     = PerspectiveManager.getPManager();
     flight = GetComponent <RealFlightControl>();
     myFlow = GetComponent <CombatFlow>();
     myRb   = GetComponent <Rigidbody>();
     ai     = GetComponent <AI_Aircraft>();
 }
Пример #28
0
    private void rpcMissileInit(int missileID)
    {
        BasicMissile missile     = PhotonNetwork.GetPhotonView(missileID).GetComponent <BasicMissile>();
        CombatFlow   missileFlow = missile.GetComponent <CombatFlow>();

        missile.myTeam   = transform.root.GetComponent <CombatFlow>().team;
        missileFlow.team = missile.myTeam;
    }
    public Vector3 calculateAttackPos(CombatFlow groundTarget)
    {
        // Master maneuvering function that handles all piloting maneuvers for attacking a given ground unit

        // Handle running in and separating

        return(groundTarget.transform.position);
    }
Пример #30
0
 void Awake()
 {
     myFlow = GetComponent <CombatFlow>();
     rbRef  = GetComponent <Rigidbody>();
     initAfterburnVolume = afterburner.volume;
     initEngineVolume    = jetEngine.volume;
     enginePitchMax      = jetEngine.pitch;
 }