private void ScanArea(NWCreature user, Location targetLocation) { NWArea area = (_.GetAreaFromLocation(targetLocation)); var spawns = SpawnService.GetAreaPlaceableSpawns(area); var spawn = spawns .Where(x => !string.IsNullOrWhiteSpace(x.SpawnPlaceable.GetLocalString("RESOURCE_RESREF")) && x.SpawnPlaceable.IsValid) .OrderBy(o => _.GetDistanceBetweenLocations(targetLocation, o.Spawn.Location)) .FirstOrDefault(); const float BaseScanningRange = 20.0f; if (spawn == null || _.GetDistanceBetweenLocations(targetLocation, spawn.SpawnLocation) > BaseScanningRange) { user.FloatingText("Couldn't locate any nearby resources..."); } else { var position = _.GetPositionFromLocation(spawn.SpawnLocation); int cellX = (int)(position.m_X / 10); int cellY = (int)(position.m_Y / 10); BiowarePosition.TurnToFaceLocation(spawn.SpawnLocation, user); user.FloatingText("Nearest resource is located at coordinates (" + cellX + ", " + cellY + ")"); } }
public void AfterTest() { _farSpawnLocation = null; _spawnLocation = null; _spawnService = null; }
public void OnOpen(string name) { Player player = new Player(_config) { Name = name, ConnectionId = Context.ConnectionId }; SpawnService.SpawnPlayer(player); _gameEngine.AddPlayer(player); Console.WriteLine($"Registered player: {player.Name} ({player.Id})"); // Confirmation status var connectionConfirmationResponse = new ConfirmConnectionResponse { Type = "connected", PlayerId = player.Id, Config = _config, MapState = _mapState, Weapons = WeaponService.Weapons }; Clients.Caller.SendAsync("connectConfirmation", connectionConfirmationResponse); Clients.All.SendAsync("newPlayerConnected", player.Name); }
public void BeforeTest() { _spawnService = new SpawnService(); _spawnLocation = new GameObject().AddComponent <MockSpawnLocationComponent>(); _spawnLocation.GetSpawnLocationResult = _spawnLocation.gameObject.transform; _spawnLocation.gameObject.transform.position = new Vector3(1.0f, 2.0f, 3.0f); _farSpawnLocation = new GameObject().AddComponent <MockSpawnLocationComponent>(); _farSpawnLocation.GetSpawnLocationResult = _farSpawnLocation.gameObject.transform; _farSpawnLocation.gameObject.transform.position = new Vector3(1000.0f, 2000.0f, 3000.0f); }
//public GUIStyle style; void OnSceneGUI() { SpawnService spawner = (SpawnService)target; GUI.color = new Color(1, 0, 0, 1); GUI.backgroundColor = Color.black; Handles.color = Color.red; //GUI.BeginGroup(Rect.zero); foreach (Vector2 spawnPoint in spawner.spawnPoints) { Handles.DrawSolidDisc(spawnPoint, Vector3.forward, 0.4f); } Handles.color = Color.green; foreach (Vector2 patrolPoint in spawner.patrolPoints) { Handles.DrawSolidDisc(patrolPoint, Vector3.forward, 0.4f); } //GUI.EndGroup(); }
public void Main() { NWPlaceable drill = _.OBJECT_SELF; string structureID = drill.GetLocalString("PC_BASE_STRUCTURE_ID"); if (string.IsNullOrWhiteSpace(structureID)) { string areaName = drill.Area.Name; Console.WriteLine("There was an error retrieving the PC_BASE_STRUCTURE_ID variable on drill in area: " + areaName); return; } Guid structureGUID = new Guid(structureID); PCBaseStructure pcStructure = DataService.PCBaseStructure.GetByID(structureGUID); PCBase pcBase = DataService.PCBase.GetByID(pcStructure.PCBaseID); PCBaseStructure tower = BaseService.GetBaseControlTower(pcBase.ID); if (tower == null) { Console.WriteLine("Could not locate valid tower in Drill OnHeartbeat. PCBaseID = " + pcBase.ID); return; } // Check whether there's space in this tower. int capacity = BaseService.CalculateResourceCapacity(pcBase.ID); int count = DataService.PCBaseStructureItem.GetNumberOfItemsContainedBy(tower.ID) + 1; if (count > capacity) { return; } BaseStructure baseStructure = DataService.BaseStructure.GetByID(pcStructure.BaseStructureID); DateTime now = DateTime.UtcNow; var outOfPowerEffect = drill.Effects.SingleOrDefault(x => _.GetEffectTag(x) == "CONTROL_TOWER_OUT_OF_POWER"); if (now >= pcBase.DateFuelEnds) { if (outOfPowerEffect == null) { outOfPowerEffect = _.EffectVisualEffect(VisualEffect.Vfx_Dur_Aura_Red); outOfPowerEffect = _.TagEffect(outOfPowerEffect, "CONTROL_TOWER_OUT_OF_POWER"); _.ApplyEffectToObject(DurationType.Permanent, outOfPowerEffect, drill); } return; } else if (now < pcBase.DateFuelEnds && outOfPowerEffect != null) { _.RemoveEffect(drill, outOfPowerEffect); } int minuteReduce = 2 * pcStructure.StructureBonus; int increaseMinutes = 60 - minuteReduce; int retrievalRating = baseStructure.RetrievalRating; if (increaseMinutes <= 20) { increaseMinutes = 20; } if (pcStructure.DateNextActivity == null) { pcStructure.DateNextActivity = now.AddMinutes(increaseMinutes); DataService.SubmitDataChange(pcStructure, DatabaseActionType.Update); } if (!(now >= pcStructure.DateNextActivity)) { return; } // Time to spawn a new item and reset the timer. var dbArea = DataService.Area.GetByResref(pcBase.AreaResref); string sector = pcBase.Sector; int lootTableID = 0; switch (sector) { case "NE": lootTableID = dbArea.NortheastLootTableID ?? 0; break; case "NW": lootTableID = dbArea.NorthwestLootTableID ?? 0; break; case "SE": lootTableID = dbArea.SoutheastLootTableID ?? 0; break; case "SW": lootTableID = dbArea.SouthwestLootTableID ?? 0; break; } if (lootTableID <= 0) { Console.WriteLine("WARNING: Loot table ID not defined for area " + dbArea.Name + ". Drills cannot retrieve items."); return; } pcStructure.DateNextActivity = now.AddMinutes(increaseMinutes); var controlTower = BaseService.GetBaseControlTower(pcStructure.PCBaseID); if (controlTower == null) { Console.WriteLine("Could not locate control tower in drill heartbeat. PCBaseID = " + pcStructure.PCBaseID); return; } var itemDetails = LootService.PickRandomItemFromLootTable(lootTableID); var tempStorage = _.GetObjectByTag("TEMP_ITEM_STORAGE"); NWItem item = _.CreateItemOnObject(itemDetails.Resref, tempStorage, itemDetails.Quantity); // Guard against invalid resrefs and missing items. if (!item.IsValid) { Console.WriteLine("ERROR: Could not create base drill item with resref '" + itemDetails.Resref + "'. Is this item valid?"); return; } if (!string.IsNullOrWhiteSpace(itemDetails.SpawnRule)) { var rule = SpawnService.GetSpawnRule(itemDetails.SpawnRule); rule.Run(item, retrievalRating); } var dbItem = new PCBaseStructureItem { PCBaseStructureID = controlTower.ID, ItemGlobalID = item.GlobalID.ToString(), ItemName = item.Name, ItemResref = item.Resref, ItemTag = item.Tag, ItemObject = SerializationService.Serialize(item) }; DataService.SubmitDataChange(pcStructure, DatabaseActionType.Update); DataService.SubmitDataChange(dbItem, DatabaseActionType.Insert); item.Destroy(); }
// Start is called before the first frame update void Awake() { instance = this; }