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); } } } }
private void setRefs() { myCombatFlow = GetComponent <CombatFlow>(); radar = GetComponent <Radar>(); rbRef = GetComponent <Rigidbody>(); flightSound = GetComponent <AudioSource>(); }
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()); }
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; } }
//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); }
//private WarningComputer warnComputer; void Awake() { myFlow = GetComponent <CombatFlow>(); myRb = GetComponent <Rigidbody>(); lockedBy = new List <CombatFlow>(); incomingMissiles = new List <CombatFlow>(); }
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; } }
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(); } } } }
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); }
// 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; } } } }
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); }
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(); } }
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); } } } }
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); }
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>(); }
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); }
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); } }
// 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); } }
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; } }
// 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); } } } }
void Awake() { pm = PerspectiveManager.getPManager(); flight = GetComponent <RealFlightControl>(); myFlow = GetComponent <CombatFlow>(); myRb = GetComponent <Rigidbody>(); ai = GetComponent <AI_Aircraft>(); }
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); }
void Awake() { myFlow = GetComponent <CombatFlow>(); rbRef = GetComponent <Rigidbody>(); initAfterburnVolume = afterburner.volume; initEngineVolume = jetEngine.volume; enginePitchMax = jetEngine.pitch; }