void BeginAttack(ZombieAttackLocation location) { int attackers = UnityEngine.Random.Range(Settings.MinAttackers, Settings.MaxAttackers); Puts($"Sending {attackers} attackers to {location}"); for (int idx = 0; idx < attackers; idx++) { Vector3 spawnPosition = GetRandomPositionNear(location.Position, 50f); BaseCombatEntity entity = SpawnAttacker(ZOMBIE_PREFAB, spawnPosition); entity.enableSaving = false; entity.Spawn(); entity.InitializeHealth(entity.StartHealth(), entity.StartMaxHealth()); ItemDefinition item = ItemManager.FindItemDefinition(WeaponItems.GetRandom()); var npc = entity.gameObject.GetComponent <NPCPlayer>(); npc.inventory.containerBelt.Clear(); npc.inventory.containerBelt.AddItem(item, 1); npc.EquipTest(); npc.SetDestination(location.Position); Puts($"Spawned attacker at {spawnPosition} equipped with {item.name}"); } PrintToChat("<color=#ff0000>THE ATTACK HAS BEGUN!</color>"); }
void InitializeTurret(BaseCombatEntity turret, float turretHealth, bool justCreated = false) { if (justCreated) { turret._health = turretHealth; } turret._maxHealth = turretHealth; if (justCreated) { turret.InitializeHealth(turretHealth, turretHealth); } else { turret.InitializeHealth(turret.health, turretHealth); } turret.startHealth = turretHealth; }
private void SpawnNpcEntity(string prefabPath, Vector3 pos) { Vector3 point; if (FindPointOnNavmesh(pos, 50, out point)) { BaseCombatEntity entity = InstantiateEntity(prefabPath, point); entity.enableSaving = false; entity.Spawn(); entity.InitializeHealth(entity.StartHealth(), entity.StartMaxHealth()); var npc = entity.gameObject.AddComponent <HumanController>(); npc.SetInfo(prefabPath, point); animalList.Add(entity); } }
private void SpawnAnimalEntity(string type, Vector3 pos) { Vector3 point; if (FindPointOnNavmesh(pos, 50, out point)) { BaseCombatEntity entity = InstantiateEntity($"assets/rust.ai/agents/{type}/{type}.prefab", point); entity.enableSaving = false; entity.Spawn(); entity.InitializeHealth(entity.StartHealth(), entity.StartMaxHealth()); entity.lifestate = BaseCombatEntity.LifeState.Alive; var npc = entity.gameObject.AddComponent <AnimalController>(); npc.SetInfo(type, point); animalList.Add(entity); } }
public GameObject DoPlacement(Construction.Target placement, Construction component) { BasePlayer ownerPlayer = base.GetOwnerPlayer(); if (!ownerPlayer) { return(null); } BaseEntity baseEntity = component.CreateConstruction(placement, true); if (!baseEntity) { return(null); } float single = 1f; float single1 = 0f; Item ownerItem = base.GetOwnerItem(); if (ownerItem != null) { baseEntity.skinID = ownerItem.skin; if (ownerItem.hasCondition) { single = ownerItem.conditionNormalized; } } baseEntity.gameObject.AwakeFromInstantiate(); BuildingBlock buildingBlock = baseEntity as BuildingBlock; if (buildingBlock) { buildingBlock.blockDefinition = PrefabAttribute.server.Find <Construction>(buildingBlock.prefabID); if (!buildingBlock.blockDefinition) { Debug.LogError("Placing a building block that has no block definition!"); return(null); } buildingBlock.SetGrade(buildingBlock.blockDefinition.defaultGrade.gradeBase.type); single1 = buildingBlock.currentGrade.maxHealth; } BaseCombatEntity baseCombatEntity = baseEntity as BaseCombatEntity; if (baseCombatEntity) { single1 = (buildingBlock != null ? buildingBlock.currentGrade.maxHealth : baseCombatEntity.startHealth); baseCombatEntity.ResetLifeStateOnSpawn = false; baseCombatEntity.InitializeHealth(single1 * single, single1); } baseEntity.gameObject.SendMessage("SetDeployedBy", ownerPlayer, SendMessageOptions.DontRequireReceiver); baseEntity.OwnerID = ownerPlayer.userID; baseEntity.Spawn(); if (buildingBlock) { Effect.server.Run("assets/bundled/prefabs/fx/build/frame_place.prefab", baseEntity, 0, Vector3.zero, Vector3.zero, null, false); } StabilityEntity stabilityEntity = baseEntity as StabilityEntity; if (stabilityEntity) { stabilityEntity.UpdateSurroundingEntities(); } return(baseEntity.gameObject); }
public GameObject DoPlacement(Construction.Target placement, Construction component) { BasePlayer ownerPlayer = this.GetOwnerPlayer(); if (!Object.op_Implicit((Object)ownerPlayer)) { return((GameObject)null); } BaseEntity construction = component.CreateConstruction(placement, true); if (!Object.op_Implicit((Object)construction)) { return((GameObject)null); } float num1 = 1f; float num2 = 0.0f; Item ownerItem = this.GetOwnerItem(); if (ownerItem != null) { construction.skinID = ownerItem.skin; if (ownerItem.hasCondition) { num1 = ownerItem.conditionNormalized; } } ((Component)construction).get_gameObject().AwakeFromInstantiate(); BuildingBlock buildingBlock = construction as BuildingBlock; if (Object.op_Implicit((Object)buildingBlock)) { buildingBlock.blockDefinition = PrefabAttribute.server.Find <Construction>(buildingBlock.prefabID); if (!(bool)((PrefabAttribute)buildingBlock.blockDefinition)) { Debug.LogError((object)"Placing a building block that has no block definition!"); return((GameObject)null); } buildingBlock.SetGrade(buildingBlock.blockDefinition.defaultGrade.gradeBase.type); num2 = buildingBlock.currentGrade.maxHealth; } BaseCombatEntity baseCombatEntity = construction as BaseCombatEntity; if (Object.op_Implicit((Object)baseCombatEntity)) { float newmax = Object.op_Inequality((Object)buildingBlock, (Object)null) ? buildingBlock.currentGrade.maxHealth : baseCombatEntity.startHealth; baseCombatEntity.ResetLifeStateOnSpawn = false; baseCombatEntity.InitializeHealth(newmax * num1, newmax); } ((Component)construction).get_gameObject().SendMessage("SetDeployedBy", (object)ownerPlayer, (SendMessageOptions)1); construction.OwnerID = ownerPlayer.userID; construction.Spawn(); if (Object.op_Implicit((Object)buildingBlock)) { Effect.server.Run("assets/bundled/prefabs/fx/build/frame_place.prefab", construction, 0U, Vector3.get_zero(), Vector3.get_zero(), (Connection)null, false); } StabilityEntity stabilityEntity = construction as StabilityEntity; if (Object.op_Implicit((Object)stabilityEntity)) { stabilityEntity.UpdateSurroundingEntities(); } return(((Component)construction).get_gameObject()); }