public ActorType GetActorType(Actor actor) { ActorType type = ActorType.Other; UnitSpawn unitSpawn = actor.GetComponent <UnitSpawn>(); if (unitSpawn as AIAircraftSpawn != null) { type = ActorType.Plane; } if (unitSpawn as AISeaUnitSpawn != null) { type = ActorType.Boat; } if (unitSpawn as AICarrierSpawn != null) { type = ActorType.Carrier; } if (unitSpawn as AIDroneCarrierSpawn != null) { type = ActorType.DroneCarrier; } if (unitSpawn as GroundUnitSpawn != null) { type = ActorType.Tank; } if (unitSpawn as ArtilleryUnitSpawn != null) { type = ActorType.Artillery; } Debug.Log(actor.name + " is a " + type.ToString()); return(type); }
//! ボタンダウンしたら呼ばれる public void OnUnitButtonDown(UnitSpawn buttonScript) { currentUnitButton = buttonScript; SetSpawnObservable(); // キャラボタンSE再生 AudioManager.Instance.PlaySE(AudioManager.SE.UNIT_BUTTON_CLICK); }
public void SetUnitToBuild(TurretBlueprint turret) { unitToBuild = turret; selectedSpawn = null; DeselectSpawn(); }
static SpawnManager() { spawnsNumber = 4; unitPrefab = Resources.Load("Unit") as GameObject; spawns = new UnitSpawn <Unit>(); mySummoner = new Summoner(true); enemySummoner = new Summoner(false); InitSpawn(); }
void Start() { unitSpawn = gameObject.GetComponent <UnitSpawn>(); enemySpawnQueue = new Queue <GameObject>(); numToSpawn = new Queue <int>(); delayTimes = new Queue <int>(); nextLevel = 1; friendlyHitEdge = false; //playLevelMain(); }
public static void SetupVisualTargetFinders(UnitSpawner __instance) { if (CheesesAITweaks.settings.enemyEjectorSeats) { Traverse unitSpawnerTraverse = Traverse.Create(__instance); UnitSpawn unitSpawn = unitSpawnerTraverse.Field("_spawnedUnit").GetValue <UnitSpawn>(); switch (__instance.unitID) { } } }
public void SelectNode(UnitSpawn spawn) { if (selectedSpawn == spawn) { DeselectSpawn(); return; } selectedSpawn = spawn; unitToBuild = null; UnitUI.SetTarget(spawn); }
public static void SetupEvasiveManuevers(UnitSpawner __instance) { if (CheesesAITweaks.settings.allAICanEvade) { Traverse unitSpawnerTraverse = Traverse.Create(__instance); UnitSpawn unitSpawn = unitSpawnerTraverse.Field("_spawnedUnit").GetValue <UnitSpawn>(); switch (__instance.unitID) { case "E-4": case "KC-49": case "AEW-50": unitSpawn.actor.gameObject.GetComponent <AIPilot>().allowEvasiveManeuvers = true; break; } } }
//TODO: These spawns are all hardcoded private List <UnitSpawn> InitTeam2Spawns() { List <UnitSpawn> spawns = new List <UnitSpawn>(); //warrior locations: HARDCODED TO 4 UNITS //warrior locations: HARDCODED TO 4 UNITS UnitSpawn warr1 = new UnitSpawn(2, 1, "warrior"); spawns.Add(warr1); UnitSpawn warr2 = new UnitSpawn(6, 1, "warrior"); spawns.Add(warr2); UnitSpawn warr3 = new UnitSpawn(12, 1, "warrior"); spawns.Add(warr3); UnitSpawn warr4 = new UnitSpawn(17, 1, "warrior"); spawns.Add(warr4); //knight locations: HARDCODED TO 2 UNITS UnitSpawn knight1 = new UnitSpawn(0, 0, "knight"); UnitSpawn knight2 = new UnitSpawn(_mapSizeX - 1, 0, "knight"); spawns.Add(knight1); spawns.Add(knight2); //Spearman locations: HARDCODED TO 2 UNITS UnitSpawn spear1 = new UnitSpawn(5, 0, "spear"); UnitSpawn spear2 = new UnitSpawn(14, 0, "spear"); spawns.Add(spear1); spawns.Add(spear2); //Wizard location UnitSpawn wizard = new UnitSpawn(9, 0, "wizard"); spawns.Add(wizard); //Leader Location UnitSpawn leader = new UnitSpawn(10, 0, "leader"); spawns.Add(leader); return(spawns); }
public void SetTarget(UnitSpawn _target) { target = _target; transform.position = target.GetBuildPos(); if (!target.isUpgraded) { upgradeCost.text = "$" + target.turretBlueprint.upgradeCost; upgradeButton.interactable = true; } else { upgradeCost.text = "DONE"; upgradeButton.interactable = false; } sellAmount.text = "$" + target.turretBlueprint.GetSellAmount(); UI.SetActive(true); }
public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId) { //if these are still null set them again (race condition?) if (_team1SpawnLocations == null) { _team1SpawnLocations = _map._team1SpawnLocations; } if (_team2SpawnLocations == null) { _team2SpawnLocations = _map._team2SpawnLocations; } GameObject player; Unit unit; //if this is the host client, spawn them on the other side of the map if (playerControllerId < NUM_UNITS_PER_TEAM) { //spawn leader if (playerControllerId == 0) { UnitSpawn leaderSpawn = _team2SpawnLocations.FirstOrDefault(s => s._unitType.Equals("leader")); player = Instantiate(Leader2, _map.TileCoordToWorldCoord(leaderSpawn._x, leaderSpawn._z), Quaternion.identity) as GameObject; unit = CreateUnit(player.GetComponent <Unit>(), leaderSpawn._x, leaderSpawn._z); UpdateCharacterStatus(player.GetComponent <CharacterStatus>(), 1); _team1SpawnLocations.Remove(leaderSpawn); } //spawn wizard else if (playerControllerId == 1) { UnitSpawn wizSpawn = _team2SpawnLocations.FirstOrDefault(s => s._unitType.Equals("wizard")); player = Instantiate(Wizard2, _map.TileCoordToWorldCoord(wizSpawn._x, wizSpawn._z), Quaternion.identity) as GameObject; unit = CreateUnit(player.GetComponent <Unit>(), wizSpawn._x, wizSpawn._z); UpdateCharacterStatus(player.GetComponent <CharacterStatus>(), 1); _team2SpawnLocations.Remove(wizSpawn); } //spawn knights else if (playerControllerId <= 3) { UnitSpawn knightSpawn = _team2SpawnLocations.FirstOrDefault(s => s._unitType.Equals("knight")); player = Instantiate(Knight2, _map.TileCoordToWorldCoord(knightSpawn._x, knightSpawn._z), Quaternion.identity) as GameObject; unit = CreateUnit(player.GetComponent <Unit>(), knightSpawn._x, knightSpawn._z); UpdateCharacterStatus(player.GetComponent <CharacterStatus>(), 1); _team2SpawnLocations.Remove(knightSpawn); } //spawn spearman else if (playerControllerId <= 5) { UnitSpawn spearSpawn = _team2SpawnLocations.FirstOrDefault(s => s._unitType.Equals("spear")); player = Instantiate(Spearman2, _map.TileCoordToWorldCoord(spearSpawn._x, spearSpawn._z), Quaternion.identity) as GameObject; unit = CreateUnit(player.GetComponent <Unit>(), spearSpawn._x, spearSpawn._z); UpdateCharacterStatus(player.GetComponent <CharacterStatus>(), 1); _team2SpawnLocations.Remove(spearSpawn); } //spawn warriors else { UnitSpawn warrSpawn = _team2SpawnLocations.FirstOrDefault(s => s._unitType.Equals("warrior")); player = Instantiate(Warrior2, _map.TileCoordToWorldCoord(warrSpawn._x, warrSpawn._z), Quaternion.identity) as GameObject; unit = CreateUnit(player.GetComponent <Unit>(), warrSpawn._x, warrSpawn._z); UpdateCharacterStatus(player.GetComponent <CharacterStatus>(), 1); _team2SpawnLocations.Remove(warrSpawn); } } else { //spawn leader if (playerControllerId == NUM_UNITS_PER_TEAM) { UnitSpawn leaderSpawn = _team1SpawnLocations.FirstOrDefault(s => s._unitType.Equals("leader")); player = Instantiate(Leader1, _map.TileCoordToWorldCoord(leaderSpawn._x, leaderSpawn._z), Quaternion.Euler(0, 180, 0)) as GameObject; unit = CreateUnit(player.GetComponent <Unit>(), leaderSpawn._x, leaderSpawn._z); UpdateCharacterStatus(player.GetComponent <CharacterStatus>(), 2); _team1SpawnLocations.Remove(leaderSpawn); } //spawn wizard else if (playerControllerId == NUM_UNITS_PER_TEAM + 1) { UnitSpawn wizSpawn = _team1SpawnLocations.FirstOrDefault(s => s._unitType.Equals("wizard")); player = Instantiate(Wizard1, _map.TileCoordToWorldCoord(wizSpawn._x, wizSpawn._z), Quaternion.Euler(0, 180, 0)) as GameObject; unit = CreateUnit(player.GetComponent <Unit>(), wizSpawn._x, wizSpawn._z); UpdateCharacterStatus(player.GetComponent <CharacterStatus>(), 2); _team1SpawnLocations.Remove(wizSpawn); } //spawn knights else if (playerControllerId <= NUM_UNITS_PER_TEAM + 3) { UnitSpawn knightSpawn = _team1SpawnLocations.FirstOrDefault(s => s._unitType.Equals("knight")); player = Instantiate(Knight1, _map.TileCoordToWorldCoord(knightSpawn._x, knightSpawn._z), Quaternion.Euler(0, 180, 0)) as GameObject; unit = CreateUnit(player.GetComponent <Unit>(), knightSpawn._x, knightSpawn._z); UpdateCharacterStatus(player.GetComponent <CharacterStatus>(), 2); _team1SpawnLocations.Remove(knightSpawn); } //spawn spearman else if (playerControllerId <= NUM_UNITS_PER_TEAM + 5) { UnitSpawn spearSpawn = _team1SpawnLocations.FirstOrDefault(s => s._unitType.Equals("spear")); player = Instantiate(Spearman1, _map.TileCoordToWorldCoord(spearSpawn._x, spearSpawn._z), Quaternion.Euler(0, 180, 0)) as GameObject; unit = CreateUnit(player.GetComponent <Unit>(), spearSpawn._x, spearSpawn._z); UpdateCharacterStatus(player.GetComponent <CharacterStatus>(), 2); _team1SpawnLocations.Remove(spearSpawn); } //spawn warriors else { UnitSpawn warrSpawn = _team1SpawnLocations.FirstOrDefault(s => s._unitType.Equals("warrior")); player = Instantiate(Warrior1, _map.TileCoordToWorldCoord(warrSpawn._x, warrSpawn._z), Quaternion.Euler(0, 180, 0)) as GameObject; unit = CreateUnit(player.GetComponent <Unit>(), warrSpawn._x, warrSpawn._z); UpdateCharacterStatus(player.GetComponent <CharacterStatus>(), 2); _team1SpawnLocations.Remove(warrSpawn); } } _units.Add(unit); NetworkServer.AddPlayerForConnection(conn, player, playerControllerId); }
/// <summary> /// This is used by the client and only the client to spawn ai vehicles. /// </summary> public static void SpawnAIVehicle(Packet packet) // This should never run on the host { if (Networker.isHost) { Debug.LogWarning("Host shouldn't be trying to spawn an ai vehicle."); return; } Message_SpawnAIVehicle message = (Message_SpawnAIVehicle)((PacketSingle)packet).message; if (!PlayerManager.gameLoaded) { Debug.LogWarning("Our game isn't loaded, adding spawn vehicle to queue"); AIsToSpawnQueue.Enqueue(packet); return; } foreach (ulong id in spawnedAI) { if (id == message.rootActorNetworkID) { Debug.Log("Got a spawnAI message for a vehicle we have already added! Name == " + message.unitName + " Returning..."); return; } } spawnedAI.Add(message.rootActorNetworkID); //Debug.Log("Got a new aiSpawn uID."); if (message.unitName == "Player") { Debug.LogWarning("Player shouldn't be sent to someones client...."); return; } Debug.Log("Trying to spawn AI " + message.aiVehicleName); GameObject prefab = UnitCatalogue.GetUnitPrefab(message.unitName); if (prefab == null) { Debug.LogError(message.unitName + " was not found."); return; } GameObject newAI = GameObject.Instantiate(prefab, VTMapManager.GlobalToWorldPoint(message.position), message.rotation); //Debug.Log("Setting vehicle name"); newAI.name = message.aiVehicleName; Actor actor = newAI.GetComponent <Actor>(); if (actor == null) { Debug.LogError("actor is null on object " + newAI.name); } if (message.redfor) { actor.team = Teams.Enemy; } else { actor.team = Teams.Allied; } AirportManager airport = newAI.GetComponent <AirportManager>(); UnitSpawn unitSP = newAI.GetComponent <UnitSpawn>(); GameObject.Destroy(unitSP); if (airport != null) { newAI.AddComponent <UnitSpawn>(); } else { newAI.AddComponent <AICarrierSpawn>(); } unitSP = newAI.GetComponent <UnitSpawn>(); UnitSpawner UnitSpawner = new UnitSpawner(); actor.unitSpawn = unitSP; actor.unitSpawn.unitSpawner = UnitSpawner; unitSP.actor = actor; Traverse.Create(actor.unitSpawn.unitSpawner).Field("_spawnedUnit").SetValue(unitSP); Traverse.Create(actor.unitSpawn.unitSpawner).Field("_spawned").SetValue(true); Traverse.Create(actor.unitSpawn.unitSpawner).Field("_unitInstanceID").SetValue(message.unitInstanceID); // To make objectives work. UnitSpawner.team = actor.team; UnitSpawner.unitName = actor.unitSpawn.unitName; if (!PlayerManager.teamLeftie) { UnitSpawner.team = actor.team; } else { if (actor.team == Teams.Enemy) { foreach (Actor subActor in newAI.GetComponentsInChildren <Actor>()) { subActor.team = Teams.Allied; TargetManager.instance.UnregisterActor(subActor); TargetManager.instance.RegisterActor(subActor); } } else if (actor.team == Teams.Allied) { foreach (Actor subActor in newAI.GetComponentsInChildren <Actor>()) { subActor.team = Teams.Enemy; TargetManager.instance.UnregisterActor(subActor); TargetManager.instance.RegisterActor(subActor); } } UnitSpawner.team = actor.team; if (airport != null) { airport.team = actor.team; SetUpCarrier(newAI, message.rootActorNetworkID, actor.team); } } TargetManager.instance.UnregisterActor(actor); TargetManager.instance.RegisterActor(actor); VTScenario.current.units.AddSpawner(actor.unitSpawn.unitSpawner); if (message.hasGroup) { VTScenario.current.groups.AddUnitToGroup(UnitSpawner, message.unitGroup); } Debug.Log(actor.name + $" has had its unitInstanceID set at value {actor.unitSpawn.unitSpawner.unitInstanceID}."); VTScenario.current.units.AddSpawner(actor.unitSpawn.unitSpawner); Debug.Log($"Spawned new vehicle at {newAI.transform.position}"); newAI.AddComponent <FloatingOriginTransform>(); newAI.transform.position = VTMapManager.GlobalToWorldPoint(message.position); newAI.transform.rotation = message.rotation; Debug.Log("This unit should have " + message.networkIDs.Length + " actors! "); int currentSubActorID = 0; foreach (Actor child in newAI.GetComponentsInChildren <Actor>()) { Debug.Log("setting up actor: " + currentSubActorID); UIDNetworker_Receiver uidReciever = child.gameObject.AddComponent <UIDNetworker_Receiver>(); uidReciever.networkUID = message.networkIDs[currentSubActorID]; if (child.gameObject.GetComponent <Health>() != null) { HealthNetworker_Receiver healthNetworker = child.gameObject.AddComponent <HealthNetworker_Receiver>(); healthNetworker.networkUID = message.networkIDs[currentSubActorID]; //HealthNetworker_Sender healthNetworkerS = newAI.AddComponent<HealthNetworker_Sender>(); //healthNetworkerS.networkUID = message.networkID; // Debug.Log("added health Sender to ai"); // Debug.Log("added health reciever to ai"); } else { Debug.Log(message.aiVehicleName + " has no health?"); } if (child.gameObject.GetComponent <ShipMover>() != null) { ShipNetworker_Receiver shipNetworker = child.gameObject.AddComponent <ShipNetworker_Receiver>(); shipNetworker.networkUID = message.networkIDs[currentSubActorID]; } else if (child.gameObject.GetComponent <GroundUnitMover>() != null) { if (child.gameObject.GetComponent <Rigidbody>() != null) { GroundNetworker_Receiver groundNetworker = child.gameObject.AddComponent <GroundNetworker_Receiver>(); groundNetworker.networkUID = message.networkIDs[currentSubActorID]; } } else if (child.gameObject.GetComponent <Rigidbody>() != null) { Rigidbody rb = child.gameObject.GetComponent <Rigidbody>(); RigidbodyNetworker_Receiver rbNetworker = child.gameObject.AddComponent <RigidbodyNetworker_Receiver>(); rbNetworker.networkUID = message.networkIDs[currentSubActorID]; } if (child.role == Actor.Roles.Air) { PlaneNetworker_Receiver planeReceiver = child.gameObject.AddComponent <PlaneNetworker_Receiver>(); planeReceiver.networkUID = message.networkIDs[currentSubActorID]; AIPilot aIPilot = child.gameObject.GetComponent <AIPilot>(); aIPilot.enabled = false; aIPilot.kPlane.SetToKinematic(); aIPilot.kPlane.enabled = false; aIPilot.commandState = AIPilot.CommandStates.Navigation; aIPilot.kPlane.enabled = true; aIPilot.kPlane.SetVelocity(Vector3.zero); aIPilot.kPlane.SetToDynamic(); RotationToggle wingRotator = aIPilot.wingRotator; if (wingRotator != null) { WingFoldNetworker_Receiver wingFoldReceiver = child.gameObject.AddComponent <WingFoldNetworker_Receiver>(); wingFoldReceiver.networkUID = message.networkIDs[currentSubActorID]; wingFoldReceiver.wingController = wingRotator; } if (aIPilot.isVtol) { //Debug.Log("Adding Tilt Controller to this vehicle " + message.networkID); EngineTiltNetworker_Receiver tiltReceiver = child.gameObject.AddComponent <EngineTiltNetworker_Receiver>(); tiltReceiver.networkUID = message.networkIDs[currentSubActorID]; } if (child.gameObject.GetComponentInChildren <ExteriorLightsController>() != null) { ExtLight_Receiver extLight = child.gameObject.AddComponent <ExtLight_Receiver>(); extLight.networkUID = message.networkIDs[currentSubActorID]; } Rigidbody rb = child.gameObject.GetComponent <Rigidbody>(); foreach (Collider collider in child.gameObject.GetComponentsInChildren <Collider>()) { if (collider) { collider.gameObject.layer = 9; } } Debug.Log("Doing weapon manager shit on " + child.gameObject.name + "."); WeaponManager weaponManager = child.gameObject.GetComponent <WeaponManager>(); if (weaponManager == null) { Debug.LogError(child.gameObject.name + " does not seem to have a weapon maanger on it."); } else { PlaneEquippableManager.SetLoadout(child.gameObject, message.networkIDs[currentSubActorID], message.normalizedFuel, message.hpLoadout, message.cmLoadout); } } AIUnitSpawn aIUnitSpawn = child.gameObject.GetComponent <AIUnitSpawn>(); if (aIUnitSpawn == null) { Debug.LogWarning("AI unit spawn is null on respawned unit " + aIUnitSpawn); } // else // newAI.GetComponent<AIUnitSpawn>().SetEngageEnemies(message.Aggresive); VehicleMover vehicleMover = child.gameObject.GetComponent <VehicleMover>(); if (vehicleMover != null) { vehicleMover.enabled = false; vehicleMover.behavior = GroundUnitMover.Behaviors.Parked; } else { GroundUnitMover ground = child.gameObject.GetComponent <GroundUnitMover>(); if (ground != null) { ground.enabled = false; ground.behavior = GroundUnitMover.Behaviors.Parked; } } Debug.Log("Checking for gun turrets on child " + child.name); if (child.gameObject.GetComponentsInChildren <Actor>().Length <= 1) {//only run this code on units without subunits Debug.Log("This is a child, with " + child.gameObject.GetComponentsInChildren <Actor>().Length + " actors, so it could have guns!"); ulong turretCount = 0; foreach (ModuleTurret moduleTurret in child.gameObject.GetComponentsInChildren <ModuleTurret>()) { TurretNetworker_Receiver tRec = child.gameObject.AddComponent <TurretNetworker_Receiver>(); tRec.networkUID = message.networkIDs[currentSubActorID]; tRec.turretID = turretCount; Debug.Log("Added turret " + turretCount + " to actor " + message.networkIDs[currentSubActorID] + " uid"); turretCount++; } ulong gunCount = 0; foreach (GunTurretAI turretAI in child.gameObject.GetComponentsInChildren <GunTurretAI>()) { turretAI.SetEngageEnemies(false); AAANetworker_Reciever aaaRec = child.gameObject.AddComponent <AAANetworker_Reciever>(); aaaRec.networkUID = message.networkIDs[currentSubActorID]; aaaRec.gunID = gunCount; Debug.Log("Added gun " + gunCount + " to actor " + message.networkIDs[currentSubActorID] + " uid"); gunCount++; } } else { Debug.Log("This isnt a child leaf thing, it has " + child.gameObject.GetComponentsInChildren <Actor>().Length + " actors"); } IRSamLauncher iLauncher = child.gameObject.GetComponent <IRSamLauncher>(); if (iLauncher != null) { //iLauncher.ml.RemoveAllMissiles(); iLauncher.ml.LoadAllMissiles(); iLauncher.SetEngageEnemies(false); MissileNetworker_Receiver mlr; //iLauncher.ml.LoadCount(message.IRSamMissiles.Length); Debug.Log($"Adding IR id's on IR SAM, len = {message.IRSamMissiles.Length}."); for (int i = 0; i < message.IRSamMissiles.Length; i++) { mlr = iLauncher.ml.missiles[i]?.gameObject.AddComponent <MissileNetworker_Receiver>(); mlr.thisML = iLauncher.ml; mlr.networkUID = message.IRSamMissiles[i]; } Debug.Log("Added IR id's."); } Soldier soldier = child.gameObject.GetComponent <Soldier>(); if (soldier != null) { soldier.SetEngageEnemies(false); if (soldier.soldierType == Soldier.SoldierTypes.IRMANPAD) { soldier.SetEngageEnemies(false); IRMissileLauncher ir = soldier.irMissileLauncher; if (ir != null) { //ir.RemoveAllMissiles(); ir.LoadAllMissiles(); MissileNetworker_Receiver mlr; //ir.LoadCount(message.IRSamMissiles.Length); Debug.Log($"Adding IR id's on manpads, len = {message.IRSamMissiles.Length}."); for (int i = 0; i < message.IRSamMissiles.Length; i++) { mlr = ir.missiles[i]?.gameObject.AddComponent <MissileNetworker_Receiver>(); mlr.thisML = ir; mlr.networkUID = message.IRSamMissiles[i]; } Debug.Log("Added IR id's on manpads."); } else { Debug.Log($"Manpad {message.networkIDs} forgot its rocket launcher pepega."); } } } Debug.Log("Checking for SAM launchers"); SAMLauncher launcher = child.gameObject.GetComponent <SAMLauncher>(); if (launcher != null) { Debug.Log("I found a sam launcher!"); SamNetworker_Reciever samNetworker = launcher.gameObject.AddComponent <SamNetworker_Reciever>(); samNetworker.networkUID = message.networkIDs[currentSubActorID]; samNetworker.radarUIDS = message.radarIDs; //Debug.Log($"Added samNetworker to uID {message.networkID}."); launcher.SetEngageEnemies(false); launcher.fireInterval = float.MaxValue; launcher.lockingRadars = null; } /*IRSamLauncher ml = actor.gameObject.GetComponentInChildren<IRSamLauncher>(); * if (ml != null) * { * ml.SetEngageEnemies(false); * MissileNetworker_Receiver lastRec; * for (int i = 0; i < ml.ml.missiles.Length; i++) * { * lastRec = ml.ml.missiles[i].gameObject.AddComponent<MissileNetworker_Receiver>(); * lastRec.networkUID = message.IRSamMissiles[i]; * lastRec.thisML = ml.ml; * } * }*/ //this code for ir missiles was here twice, so i dissable the seccond copy Debug.Log("Checking for locking radars"); foreach (LockingRadar radar in child.GetComponentsInChildren <LockingRadar>()) { if (radar.GetComponent <Actor>() == child) { Debug.Log($"Adding radar receiver to object {child.name} as it is the same game object as this actor."); LockingRadarNetworker_Receiver lastLockingReceiver = child.gameObject.AddComponent <LockingRadarNetworker_Receiver>(); lastLockingReceiver.networkUID = message.networkIDs[currentSubActorID]; Debug.Log("Added locking radar!"); } else if (radar.GetComponentInParent <Actor>() == child) { Debug.Log($"Adding radar receiver to object {child.name} as it is a child of this actor."); LockingRadarNetworker_Receiver lastLockingReceiver = child.gameObject.AddComponent <LockingRadarNetworker_Receiver>(); lastLockingReceiver.networkUID = message.networkIDs[currentSubActorID]; Debug.Log("Added locking radar!"); } else { Debug.Log("This radar is not direct child of this actor, ignoring"); } } AIVehicles.Add(new AI(child.gameObject, message.aiVehicleName, child, message.networkIDs[currentSubActorID])); Debug.Log("Spawned in AI " + child.gameObject.name); if (!VTOLVR_Multiplayer.AIDictionaries.allActors.ContainsKey(message.networkIDs[currentSubActorID])) { VTOLVR_Multiplayer.AIDictionaries.allActors.Add(message.networkIDs[currentSubActorID], child); } if (!VTOLVR_Multiplayer.AIDictionaries.reverseAllActors.ContainsKey(actor)) { VTOLVR_Multiplayer.AIDictionaries.reverseAllActors.Add(child, message.networkIDs[currentSubActorID]); } currentSubActorID++; } }
public void addSpawn(UnitSpawn spawn) { unitSpawnStateMap.Add(spawn.spawn.name, spawn); }
public void DeselectSpawn() { selectedSpawn = null; UnitUI.Hide(); }
static void Postfix(UnitSpawner __instance) { if (Networker.isHost) { UnitSpawn sp = (UnitSpawn)Traverse.Create(__instance).Field("_spawnedUnit").GetValue(); if (sp == null) { return; } Actor actor = sp.actor; if (actor.isPlayer) { return; } TargetManager.instance.RegisterActor(actor); AIManager.setupAIAircraft(actor); /*Debug.Log("Setting up new AI."); * * Debug.Log("Telling client about newly spawned AI."); * Actor actor = __instance.actor; * if (!actor.isPlayer) * { * if (actor.name.Contains("Client")) * return; * bool Aggresion = false; * if (actor.gameObject.GetComponent<UIDNetworker_Sender>() != null) * { * Debug.Log("Try sending ai " + actor.name + " to client."); * HPInfo[] hPInfos2 = null; * int[] cmLoadout = null; * UIDNetworker_Sender uidSender = actor.gameObject.GetComponent<UIDNetworker_Sender>(); * if (actor.role == Actor.Roles.Air) * { * WeaponManager wm = actor.gameObject.GetComponent<WeaponManager>(); * if (wm != null) * hPInfos2 = PlaneEquippableManager.generateHpInfoListFromWeaponManager(actor.weaponManager, PlaneEquippableManager.HPInfoListGenerateNetworkType.sender, uidSender.networkUID).ToArray(); * } * AIUnitSpawn aIUnitSpawn = actor.gameObject.GetComponent<AIUnitSpawn>(); * if (aIUnitSpawn == null) * { * Debug.LogWarning("AI unit spawn is null on ai " + actor.name); * } * else * { * Aggresion = aIUnitSpawn.engageEnemies; * } * bool canBreak = false; * PhoneticLetters letters = new PhoneticLetters(); * foreach (var Group in VTScenario.current.groups.GetExistingGroups(actor.team)) * { * foreach (var ID in Group.unitIDs) * { * if (ID == actor.unitSpawn.unitID) * { * letters = Group.groupID; * canBreak = true; * break; * } * } * if (canBreak) * break; * } * List<ulong> ids = new List<ulong>(); * ulong lastID; * SAMLauncher launcher = actor.gameObject.GetComponentInChildren<SAMLauncher>(); * if (launcher != null) * { * foreach (var radar in launcher.lockingRadars) * { * if (radar.myActor == null) * { * Debug.LogError("Locking radar on one of the SAM's is literally null."); * } * if (VTOLVR_Multiplayer.AIDictionaries.reverseAllActors.TryGetValue(radar.myActor, out lastID)) * { * ids.Add(lastID); * // Debug.Log("Aded a radar ID"); * } * else * Debug.LogError("Couldn't get a locking radar on one of the SAM's, probably a dictionary problem."); * } * } * ulong[] irIDS = new ulong[0]; * IRSAMNetworker_Sender irs = actor.gameObject.GetComponentInChildren<IRSAMNetworker_Sender>(); * if (irs != null) * { * irIDS = irs.irIDs; * } * Debug.Log("Finally sending AI " + actor.name + " to client all clients."); * if (canBreak) * { * NetworkSenderThread.Instance.SendPacketAsHostToAllClients(new Message_SpawnAIVehicle(actor.name, AIManager.GetUnitNameFromCatalog(actor.unitSpawn.unitName), * VTMapManager.WorldToGlobalPoint(actor.gameObject.transform.position), * new Vector3D(actor.gameObject.transform.rotation.eulerAngles), uidSender.networkUID, hPInfos2, cmLoadout, 0.65f, Aggresion, actor.unitSpawn.unitSpawner.unitInstanceID, letters, ids.ToArray(), irIDS), * EP2PSend.k_EP2PSendReliable); * } * else * { * // Debug.Log("It seems that " + actor.name + " is not in a unit group, sending anyways."); * NetworkSenderThread.Instance.SendPacketAsHostToAllClients(new Message_SpawnAIVehicle(actor.name, AIManager.GetUnitNameFromCatalog(actor.unitSpawn.unitName), * VTMapManager.WorldToGlobalPoint(actor.gameObject.transform.position), * new Vector3D(actor.gameObject.transform.rotation.eulerAngles), uidSender.networkUID, hPInfos2, cmLoadout, 0.65f, Aggresion, actor.unitSpawn.unitSpawner.unitInstanceID, ids.ToArray(), irIDS), * EP2PSend.k_EP2PSendReliable); * } * } * else * { * Debug.Log("Could not find the UIDNetworker_Sender"); * } * }*/ AIManager.TellClientAboutAI(new Steamworks.CSteamID(0)); } }
public static void SetupEjection(UnitSpawner __instance) { if (CheesesAITweaks.settings.enemyEjectorSeats) { Traverse unitSpawnerTraverse = Traverse.Create(__instance); UnitSpawn unitSpawn = unitSpawnerTraverse.Field("_spawnedUnit").GetValue <UnitSpawn>(); switch (__instance.unitID) { case "ASF-30": AIEjectPilot eject = CheesesAITweaks.instance.AddEjectorSeat(unitSpawn.actor.health, unitSpawn.GetComponent <Rigidbody>(), new Vector3(0, 0, 8)); GameObject canopy = unitSpawn.actor.transform.Find("enemyFighterNS").Find("canopy").gameObject; eject.OnBegin.AddListener(delegate { canopy.SetActive(false); }); GameObject cockpit = CheesesAITweaks.instance.AddFACockpit(unitSpawn.transform, new Vector3(0, 0.27729f, 6.581f), Vector3.one * 100); eject.OnBegin.AddListener(delegate { cockpit.SetActive(true); }); break; case "ASF-33": AIEjectPilot eject2 = CheesesAITweaks.instance.AddEjectorSeat(unitSpawn.actor.health, unitSpawn.GetComponent <Rigidbody>(), new Vector3(0, 0.3f, 8)); GameObject canopy2 = unitSpawn.actor.transform.Find("lod0").Find("canopy").gameObject; eject2.OnBegin.AddListener(delegate { canopy2.SetActive(false); }); GameObject cockpit2 = CheesesAITweaks.instance.AddFACockpit(unitSpawn.transform, new Vector3(0, 0.465f, 6.581f), Vector3.one * 100); eject2.OnBegin.AddListener(delegate { cockpit2.SetActive(true); }); break; case "ASF-58": AIEjectPilot eject3 = CheesesAITweaks.instance.AddEjectorSeat(unitSpawn.actor.health, unitSpawn.GetComponent <Rigidbody>(), new Vector3(0, 0.025f, 14.122f)); GameObject canopy3 = unitSpawn.actor.transform.Find("body").Find("canopy").gameObject; eject3.OnBegin.AddListener(delegate { canopy3.SetActive(false); }); AIEjectPilot eject6 = CheesesAITweaks.instance.AddEjectorSeat(unitSpawn.actor.health, unitSpawn.GetComponent <Rigidbody>(), new Vector3(0, 0.41f, 12.126f)); eject6.OnBegin.AddListener(delegate { canopy3.SetActive(false); }); GameObject cockpit3 = CheesesAITweaks.instance.AddFACockpit(unitSpawn.transform, new Vector3(0, 0.107f, 11.57f), Vector3.one * 125); eject3.OnBegin.AddListener(delegate { cockpit3.SetActive(true); }); eject6.OnBegin.AddListener(delegate { cockpit3.SetActive(true); }); break; case "GAV-25": CheesesAITweaks.instance.AddEjectorSeat(unitSpawn.actor.health, unitSpawn.GetComponent <Rigidbody>(), new Vector3(0, -0.7f, 4.2f)); break; case "EBomberAI": AIEjectPilot eject4 = CheesesAITweaks.instance.AddEjectorSeat(unitSpawn.actor.health, unitSpawn.GetComponent <Rigidbody>(), new Vector3(-0.629f, 0.397f, 23.806f)); AIEjectPilot eject5 = CheesesAITweaks.instance.AddEjectorSeat(unitSpawn.actor.health, unitSpawn.GetComponent <Rigidbody>(), new Vector3(0.629f, 0.397f, 23.806f)); GameObject canopy4 = unitSpawn.actor.transform.Find("CockpitPart").Find("ejectPanelLeft").gameObject; eject4.OnBegin.AddListener(delegate { canopy4.SetActive(false); }); GameObject canopy5 = unitSpawn.actor.transform.Find("CockpitPart").Find("ejectPanelRight").gameObject; eject5.OnBegin.AddListener(delegate { canopy5.SetActive(false); }); CheesesAITweaks.instance.AddBomberDoors(unitSpawn.actor.transform, eject4, false); CheesesAITweaks.instance.AddBomberDoors(unitSpawn.actor.transform, eject5, true); unitSpawn.transform.Find("CockpitPart").GetComponent <VehiclePart>().detachDelay = new MinMax(3, 8); break; case "E-4": case "AEW-50": AICrewBailer crewBailer = unitSpawn.actor.gameObject.AddComponent <AICrewBailer>(); crewBailer.SetupCrew(15, unitSpawn.GetComponent <Rigidbody>()); unitSpawn.actor.health.OnDeath.AddListener(crewBailer.BeginBailout); break; case "KC-49": AICrewBailer crewBailer2 = unitSpawn.actor.gameObject.AddComponent <AICrewBailer>(); crewBailer2.SetupCrew(3, unitSpawn.GetComponent <Rigidbody>()); unitSpawn.actor.health.OnDeath.AddListener(crewBailer2.BeginBailout); break; default: break; } } }
public static void SetupGooglyEyes(UnitSpawner __instance) { if (CheesesAITweaks.settings.eyes) { Traverse unitSpawnerTraverse = Traverse.Create(__instance); UnitSpawn unitSpawn = unitSpawnerTraverse.Field("_spawnedUnit").GetValue <UnitSpawn>(); switch (__instance.unitID) { case "FA-26B AI": CheesesAITweaks.instance.AddGooglyEye(unitSpawn.transform, new Vector3(0.66f, 1.254f, 5.922f), new Vector3(-20f, 70f, 0f), 1f, true); break; case "F-45A AI": CheesesAITweaks.instance.AddGooglyEye(unitSpawn.transform, new Vector3(0.536f, 0.907f, 5.73f), new Vector3(-20f, 70f, 0f), 1f, true); break; case "MQ-31": CheesesAITweaks.instance.AddGooglyEye(unitSpawn.transform, new Vector3(0.923f, 0.907f, 5.73f), new Vector3(-20f, 80f, 0f), 1f, true); break; case "ASF-30": CheesesAITweaks.instance.AddGooglyEye(unitSpawn.transform, new Vector3(0.675f, 1.13f, 8.16f), new Vector3(-20f, 80f, 0f), 1.2f, true); break; case "ASF-33": CheesesAITweaks.instance.AddGooglyEye(unitSpawn.transform, new Vector3(0.661f, 1.337f, 8.517f), new Vector3(-25f, 80f, 0f), 1.2f, true); break; case "ASF-58": CheesesAITweaks.instance.AddGooglyEye(unitSpawn.transform, new Vector3(1.01f, 1.215f, 12.74f), new Vector3(-30f, 80f, 0f), 2f, true); break; case "AIUCAV": CheesesAITweaks.instance.AddGooglyEye(unitSpawn.transform, new Vector3(1.01f, 0.63f, 2.65f), new Vector3(-70, 60, 0), 2f, true); break; case "KC-49": CheesesAITweaks.instance.AddGooglyEye(unitSpawn.transform, new Vector3(3.19f, 1.439f, 32.283f), new Vector3(-20, 80, 0), 3f, true); CheesesAITweaks.instance.AddGooglyEye(unitSpawn.transform, new Vector3(1.349f, -2.849f, -24.2753f), new Vector3(60, 150, 0), 2f, true); break; case "E-4": case "AEW-50": CheesesAITweaks.instance.AddGooglyEye(unitSpawn.transform, new Vector3(3.19f, 1.439f, 32.283f), new Vector3(-20, 80, 0), 3f, true); CheesesAITweaks.instance.AddGooglyEye(unitSpawn.transform, new Vector3(2f, 12.85f, -2.371f), new Vector3(0, 10, 0), 2f, true); break; case "AV-42CAI": CheesesAITweaks.instance.AddGooglyEye(unitSpawn.transform, new Vector3(0.988f, 0.119f, 5.543f), new Vector3(-5, 80, 0), 1f, true); break; case "GAV-25": CheesesAITweaks.instance.AddGooglyEye(unitSpawn.transform, new Vector3(0.872f, 0.472f, 4.464f), new Vector3(-15, 80, 0), 1f, true); break; case "ABomberAI": case "EBomberAI": CheesesAITweaks.instance.AddGooglyEye(unitSpawn.transform, new Vector3(0.788f, -1.08f, 22.465f), new Vector3(70, 90, 0), 1.5f, true); break; default: break; } } }