public async Task <IActionResult> PutHut(int id, Hut hut) { if (id != hut.Id) { return(BadRequest()); } _context.Entry(hut).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HutExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Hut> > PostHut(Hut hut) { _context.HutItems.Add(hut); await _context.SaveChangesAsync(); return(CreatedAtAction("GetHut", new { id = hut.Id }, hut)); }
void Place() { if (Cursor.CheckPlacement() == false) { return; } PixelCrushers.MessageSystem.SendMessage(this, "PropPlaced", CurrentItem.Name); GameObject spawnObj = Instantiate(ReferencedObject, Cursor.transform.position, Cursor.transform.rotation); spawnObj.transform.position = Cursor.transform.position; spawnObj.transform.rotation = Cursor.transform.rotation; spawnObj.GetComponent <ObjectPosition>().AdjustPositions(); if (spawnObj.GetComponent <OccupySpace>() != null) { if (spawnObj.GetComponent <OccupySpace>().isActiveAndEnabled) { spawnObj.GetComponent <OccupySpace>().OccupyTiles(); } } PlayerInventory.RemoveItem(CurrentItem); if (spawnObj.GetComponent <Hut>() != null) { Hut hut = spawnObj.GetComponent <Hut>(); hut.Init(); BlossomManager.Instance.AddHut(hut.Name); } if (spawnObj.GetComponent <PixelCrushers.SpawnedObject>() != null) { PixelCrushers.SpawnedObject spawnedObject = spawnObj.GetComponent <PixelCrushers.SpawnedObject>(); spawnedObject.key += " PlayerPlaced"; } AstarPath.active.Scan(); }
public static void AttemptSpawnVillager() { if (!AtVillagerCapacity()) { var hut = Hut.RandomHut(); hut.SpawnVillager(); } }
private void AddFamilyWithHome(Model.Settlement.Settlement settlement) { Family family = new VarskFamilyFactory(settlement.SettlerManager).Generate(); settlement.SettlerManager.Add(family); Residence residence = new Hut(); settlement.Buildings.Add(residence); residence.AddResident(family); }
public async Task <ActionResult <Hut> > PostHut(Hut hut) { //if (ModelState.IsValid) //{ // return BadRequest(); //} _context.Huts.Add(hut); await _context.SaveChangesAsync(); return(CreatedAtAction("GetHut", new { id = hut.Id }, hut)); }
void Awake() { killedOrks = new HashSet <Ork>(); Hut.ResetAll(); Fort.ResetAll(); Villager.ResetAll(); Ork.ResetAll(); SecondsOfPlay = 0; villagersHaveSpawned = false; FireBreathed = 0f; }
void FindNextBuildSite() { var location2D = spawner.NextLocation(); var location3D = new Vector3(location2D.x, hut.transform.position.y, location2D.y); if (Hut.AllHuts().All(h => Vector3.Distance(h.transform.position, location3D) >= minimumHutSpace)) { nextLocation = location2D; currentState = BuildState.AssemblingBuilders; } }
public override void Init() { hut = GetComponent <Hut>(); storage = GetComponent <Storage>(); sink = GetComponent <ResourceSink>(); hut.health = storage.health = sink.health = health; hut.owner = storage.owner = sink.owner = owner; hut.refreshPerformTime = storage.refreshPerformTime = sink.refreshPerformTime = refreshPerformTime; hut.Init(); // Spawn in starting units for (int i = 0; i < 5; i++) { hut.Perform(); } StartTask(); }
public static int TotalVillagerCapacity() { return(Hut.AllHuts().Count() * numberPerHut); }
/// <summary> /// Parse the html content from the hut booking page to scrape information like name, location, and hut website /// </summary> /// <param name="hutId"></param> /// <param name="doc"></param> /// <param name="isNewHut"></param> /// <param name="log"></param> /// <returns></returns> public static async Task <Hut> ParseHutInformation(int hutId, HtmlDocument doc, bool isNewHut, ILogger log) { var infoDiv = doc.DocumentNode.SelectSingleNode("//body").Descendants("div").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value == "info").FirstOrDefault(); if (infoDiv != null) { string hutName = infoDiv.ChildNodes["h4"].InnerText; if (string.IsNullOrEmpty(hutName)) { log.LogWarning($"HutName empty. Ignoring hutid={hutId}"); return(null); } var hut = new Hut() { Id = hutId, Name = hutName }; var spans = infoDiv.ChildNodes.Where(c => c.Name == "span").ToArray(); // We use the phone number only as a way to determine the country string phoneNumber = spans[1]?.InnerText; log.LogDebug($"Phonenumber={phoneNumber}"); string coordinates = spans[4]?.InnerText; coordinates = Regex.Replace(coordinates, @"\s+", " "); coordinates = Regex.Replace(coordinates, "Koordinaten: ", ""); hut.Coordinates = coordinates; var logoDiv = doc.DocumentNode.SelectSingleNode("//body").Descendants("div").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value == "logo").FirstOrDefault(); var hutWebsiteUrl = logoDiv?.Descendants("a").Where(d => d.Attributes.Contains("href")).Select(a => a.Attributes["href"].Value).FirstOrDefault(); if (!string.IsNullOrEmpty(hutWebsiteUrl)) { if (!hutWebsiteUrl.ToLower().StartsWith("http")) { hutWebsiteUrl = "http://" + hutWebsiteUrl; } hut.HutWebsite = hutWebsiteUrl; } hut.Enabled = !doc.ParsedText.Contains("Diese Hütte ist nicht freigeschaltet"); string country = null; string region = null; // Only call the external services, if the hut is a new one for us if (isNewHut) { var latLong = await SearchHutCoordinates(hutName, log); if (latLong.latitude != null && latLong.longitude != null) { hut.Latitude = latLong.latitude; hut.Longitude = latLong.longitude; var countryRegion = await GetCountryAndRegion((double)latLong.latitude, (double)latLong.longitude, log); country = countryRegion.country ?? country; region = countryRegion.region; } if (string.IsNullOrEmpty(country)) { // Fallback solution to roughly determine the country a hut is based in. This is not alway accurate country = GetCountry(hutName, phoneNumber, doc.ParsedText); } } hut.Country = country; hut.Region = region; hut.LastUpdated = DateTime.UtcNow; log.LogInformation($"Hut info parsed: id={hutId} name={hut.Name} country={hut.Country} region={hut.Region} hutEnabled={hut.Enabled} lat={hut.Latitude} long={hut.Longitude} coordinates={hut.Coordinates}"); return(hut); } log.LogError("Please pass valid hut html page in the request body"); return(null); }
// Use this for initialization void Start() { // Set up lizard dict lizards.Add(Lizard.Assignment.HATCHERY, new List <Lizard>()); lizards.Add(Lizard.Assignment.TRAP, new List <Lizard>()); lizards.Add(Lizard.Assignment.TAILOR, new List <Lizard>()); lizards.Add(Lizard.Assignment.WORKER, new List <Lizard>()); lizards.Add(Lizard.Assignment.FARMER, new List <Lizard>()); // Set up resource dict unclaimedResources.Add(Resource.ResourceType.METAL, new List <Resource>()); unclaimedResources.Add(Resource.ResourceType.GEMS, new List <Resource>()); unclaimedResources.Add(Resource.ResourceType.MUSHROOMS, new List <Resource>()); unclaimedResources.Add(Resource.ResourceType.HUMAN_FOOD, new List <Resource>()); unclaimedResources.Add(Resource.ResourceType.HUMAN_SKIN, new List <Resource>()); unclaimedResources.Add(Resource.ResourceType.BONES, new List <Resource>()); for (int ii = 0; ii < width; ++ii) { for (int jj = 0; jj < depth; ++jj) { tiles[ii, jj] = Instantiate <TileBase>(prefabs[(int)TileBase.TileType.FILLED]); tiles[ii, jj].isConstructed = true; tiles[ii, jj].SetCoords(ii, jj); tiles[ii, jj].transform.SetParent(transform); } } for (int i = 0; i < width - 1; i++) { for (int j = 0; j < depth; j++) { connectionsLR[i, j] = Instantiate <SpriteRenderer>(connectionPrefabLR); connectionsLR[i, j].transform.SetParent(transform); connectionsLR[i, j].transform.position = new Vector3(i + 1.0f - TileManager.width / 2, -0.5f - j, -2.1f); connectionsLR[i, j].enabled = false; } } for (int i = 0; i < width; i++) { for (int j = 0; j < depth - 1; j++) { connectionsUD[i, j] = Instantiate <SpriteRenderer>(connectionPrefabUD); connectionsUD[i, j].transform.SetParent(transform); connectionsUD[i, j].transform.position = new Vector3(i + 0.5f - TileManager.width / 2, -j - 1.0f, -2.1f); connectionsUD[i, j].enabled = false; } } Debug.Log("Create starting city"); hutTile = RequestNewTile(width - 6, 0, TileBase.TileType.HUT, true) as Hut; for (int i = 0; i < 6; i++) { Instantiate <Resource> (foodPrefab).PutInRoom(hutTile); } RequestNewTile(width - 6, 1, TileBase.TileType.STORAGE, true); RequestNewTile(width - 5, 1, TileBase.TileType.FARM, true); // ------------------ // DEBUG CODE //for(int i = 0; i < 6; i++) //Instantiate<Resource>(humanSkinPrefab).PutInRoom(hutTile); // RequestNewTile(width - 5, 2, TileBase.TileType.TAILOR, true); // --------------- for (int i = 0; i < 6; i++) { int x = Random.Range(0, width), y = Random.Range(0, 7); if (tiles[x, y].Type() == TileBase.TileType.FILLED) { RequestNewTile(x, y, TileBase.TileType.BONES, true); } } for (int i = 0; i < 10; i++) { int x = Random.Range(0, width), y = Random.Range(0, 7); if (tiles[x, y].Type() == TileBase.TileType.FILLED) { RequestNewTile(x, y, TileBase.TileType.METAL, true); } } for (int i = 0; i < 2; i++) { int x = Random.Range(0, width), y = Random.Range(0, 7); if (tiles[x, y].Type() == TileBase.TileType.FILLED) { RequestNewTile(x, y, TileBase.TileType.GEMS, true); } } for (int i = 0; i < 40; i++) { int x = Random.Range(0, width), y = Random.Range(8, depth); if (tiles[x, y].Type() == TileBase.TileType.FILLED) { RequestNewTile(x, y, TileBase.TileType.METAL, true); } } for (int i = 0; i < 16; i++) { int x = Random.Range(0, width), y = Random.Range(8, depth); if (tiles[x, y].Type() == TileBase.TileType.FILLED) { RequestNewTile(x, y, TileBase.TileType.GEMS, true); } } }
public void Escape() { Hut?.RemoveLumberjack(this); mSoundEmitter.Dispose(); }
public void Escape() { Hut?.RemoveDoubleAxeKiller(this); mSoundEmitter.Dispose(); }
public static void AddToPool(Hut toAdd) { hutList.Add(toAdd); }
public void LoadContent(GraphicsDeviceManager deviceManager, ContentManager contentManager, int windowWidth, int windowHeight) { var currentDirectoryPath = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory("../../../../Content"); var graphicsDevice = deviceManager.GraphicsDevice; // Create a new content manager so we can unload all its content later mContentManager = new ContentManager(contentManager.ServiceProvider, contentManager.RootDirectory); mSpriteBatch = new SpriteBatch(graphicsDevice); var font = mContentManager.Load <SpriteFont>("Font"); var modelLoader = new ModelLoader(graphicsDevice); var texture2D = UIv2.Menu.CreateTexture2D(graphicsDevice, 50, 30, pixel => Color.Black); mMenu = new UIv2.Menu(graphicsDevice, 0, 0, 100, 4); mMenu.NonSolid(); mLabel = new UIv2.Components.Label(graphicsDevice, 0, 0, 25, 100, "", font, Color.Orange); mLabel.AddTo(mMenu); var backButton = new UIv2.Components.Button(graphicsDevice, 90, 0, 10, 100, texture2D, "Back", font, Color.White); backButton.AddTo(mMenu); backButton.AddListener(MouseButtons.Left, InputState.Pressed, () => { ScreenManager.Remove(this); IsVisible = false; }); mRenderTarget = new RenderTarget(graphicsDevice, Options.ResolutionWidth, Options.ResolutionHeight, 1); mMasterRenderer = new MasterRenderer(graphicsDevice, mContentManager) { DebugMode = false }; mCamera = new Camera(farPlane: Options.ViewingDistance, nearPlane: 0.5f, thirdPerson: true, location: new Vector3(0.0f, 0.0f, -110.0f)); mCameraHandler = new CameraHandler(mCamera, 4.0f, 2.0f, .3f); mScene = new Scene(); var staticObjectsRectangles = new List <CollisionRectangle>(); mScene.mQuadTree = new QuadTree <Actor>(new Rectangle(-128, -128, 256, 256), 4, 10); mScene.mTerrain = new Terrain(mContentManager, graphicsDevice, "Terrain/level1 heightmap.png", "Terrain/techdemoTexture.png"); mScene.Add(mScene.mTerrain); var obstacleMesh = modelLoader.LoadMesh("Mesh/beerbottle2.obj"); var random = new Random(); for (var i = 0; i < ObstacleCount; i++) { var x = (2.0f * (float)random.NextDouble() - 1.0f) * ObstacleRadius; var z = (2.0f * (float)random.NextDouble() - 1.0f) * ObstacleRadius; var vector = new Vector3(x, 0.0f, z) + new Vector3(20.0f, 0.0f, -100.0f); vector.Y = mScene.mTerrain.GetHeight(vector); var actor = new Actor(obstacleMesh) { ModelMatrix = Matrix.CreateTranslation(vector) }; mScene.Add(actor); mScene.mQuadTree.Insert(actor, actor.mBoundingRectangle.GetAxisAlignedRectangle(1)); staticObjectsRectangles.Add(actor.mBoundingRectangle); } mScene.mVisibilityGraph = new Pathfinding.VisibilityGraph(staticObjectsRectangles, new Rectangle(-128, -128, 256, 256), 0.0f, false); var hutMesh = modelLoader.LoadMesh("Mesh/spawningcabin_scaled 0.015.fbx"); var lumberjackMesh = modelLoader.LoadMesh("Mesh/lumberjack_minimal_noanimation.obj"); var doubleAxeKillerMesh = modelLoader.LoadMesh("Mesh/lumberjack_distance_idle.fbx"); modelLoader.LoadAnimation(doubleAxeKillerMesh, "Mesh/lumberjack_distance_walk.fbx"); modelLoader.LoadAnimation(doubleAxeKillerMesh, "Mesh/lumberjack_distance_hit.fbx"); modelLoader.LoadAnimation(doubleAxeKillerMesh, "Mesh/lumberjack_distance_run.fbx"); var axeMesh = modelLoader.LoadMesh("Mesh/axe.fbx"); var silverbackMesh = modelLoader.LoadMesh("Mesh/gorilla_idle.fbx"); modelLoader.LoadAnimation(silverbackMesh, "Mesh/gorilla_walking.fbx"); modelLoader.LoadAnimation(silverbackMesh, "Mesh/gorilla_smash.fbx"); var capuchinMesh = modelLoader.LoadMesh("Mesh/kapuziner_idle.fbx"); modelLoader.LoadAnimation(capuchinMesh, "Mesh/kapuziner_walk.fbx"); modelLoader.LoadAnimation(capuchinMesh, "Mesh/kapuziner_heal.fbx"); mSilverback = new Silverback(new Vector3(0.0f, 0.0f, -110.0f), new Vector2(0.0f), silverbackMesh); mScene.Add(mSilverback); var otherSilverback = new Silverback(new Vector3(0.0f, 0.0f, -110.0f), new Vector2(0.0f), silverbackMesh); mSubApe = new Capuchin(capuchinMesh, mScene.mTerrain, otherSilverback, mScene, ref random); mScene.Add(mSubApe); var hut = new Hut(hutMesh, lumberjackMesh, doubleAxeKillerMesh, axeMesh, mSilverback, mScene, 1000, 100.0f, 110.0f, true); mScene.Add(hut); mScene.mPostProcessing.mBloom.Activated = false; mScene.mPostProcessing.mFxaa.Activated = false; mScene.mSky.Light.mShadow.mActivated = false; mCamera.UpdatePerspective(); Directory.SetCurrentDirectory(currentDirectoryPath); }
/// <summary> /// Load a file, read relevant infos from it and build level /// </summary> public void Load(string filename) { /* File is build up like this line by line(for now) * 1. Light information x,y,z * 1. Heightmap path * 2. Heightmap texture path * 3. M Mesh1 (including relative path to mesh? and other relevant informations) * 4. A Actor1 using Mesh1 is represented by following information: x,z,rotation,(scale?) * 5. A Actor2 using Mesh1 is represented by following information: x,z,rotation,(scale?) * 6. ...... * n. Mesh2 (including relative path to mesh? and other relevant informations) * k. EOF (end of file, stream reader stops reading) */ var currentDirectoryPath = Directory.GetCurrentDirectory(); if (currentDirectoryPath.EndsWith("Content") || currentDirectoryPath.EndsWith("Content/") || currentDirectoryPath.EndsWith("Content\\")) { Directory.SetCurrentDirectory("..\\bin\\Windows\\x86\\Debug\\"); } mLevelFilename = filename; try { using (var sr = new StreamReader(filename)) { var directoryPath = Path.GetDirectoryName(filename); Directory.SetCurrentDirectory(directoryPath); // Load/build terrain mTerrain = new Terrain(mContentManager, mDevice, sr.ReadLine(), sr.ReadLine()); mTerrain.mGrass.mActivated = Options.GraphicsQuality > 0 ? true : false; var mCollisionRectangles = new List <CollisionRectangle>(); string line; Mesh mesh = null; // Load the rest (objects and actors and light) while ((line = sr.ReadLine()) != null) { var lineSub = line.Substring(2); if (line.StartsWith("M ")) { // Read the path to the mesh mesh = mModelLoader.LoadMesh(lineSub); mesh.Path = lineSub; } else if (line.StartsWith("A ")) { var strings = lineSub.Split(' '); var actorLocation = strings[0].Split(','); var actorRotation = strings[1].Split(','); var actorOffset = strings[2]; var x = StringToFloat(actorLocation[0]); var z = StringToFloat(actorLocation[1]); var qX = StringToFloat(actorRotation[0]); var qY = StringToFloat(actorRotation[1]); var qZ = StringToFloat(actorRotation[2]); var qW = StringToFloat(actorRotation[3]); var offset = StringToFloat(actorOffset); var vector = new Vector3(x, 0.0f, z); vector.Y = mTerrain.GetHeight(vector) - offset; var quaternion = new Quaternion(qX, qY, qZ, qW); var matrix = Matrix.CreateFromQuaternion(quaternion) * Matrix.CreateTranslation(vector); var actor = new Actor(mesh) { ModelMatrix = matrix }; // We dont want to allow actors which hover above the ground to be in the collision caluc if (-offset < mesh.mMeshData.mBoundingSphere.Radius && actor.mBoundingRectangle.mCollidable) { mQuadTree.Insert(actor, actor.mBoundingRectangle.GetAxisAlignedRectangle(1)); mCollisionRectangles.Add(actor.mBoundingRectangle); } Add(actor); } else if (line.StartsWith("L ")) { var strings = lineSub.Split(' '); var time = strings[0]; var lightColor = strings[1].Split(','); var lightAmbient = strings[2]; var light = mSky.Light; mSky.mTime = StringToFloat(time); light.mColor.X = StringToFloat(lightColor[0]); light.mColor.Y = StringToFloat(lightColor[1]); light.mColor.Z = StringToFloat(lightColor[2]); light.mAmbient = StringToFloat(lightAmbient); } else if (line.StartsWith("B ")) { var strings = lineSub.Split(' '); var threshold = strings[0]; var power = strings[1]; var intensity = strings[2]; mPostProcessing.mBloom.mThreshold = StringToFloat(threshold); mPostProcessing.mBloom.mPower = StringToFloat(power); mPostProcessing.mBloom.mIntensity = StringToFloat(intensity); } else if (line.StartsWith("F ")) { var strings = lineSub.Split(' '); var lumaThreshold = strings[0]; var lumaThresholdMin = strings[1]; mPostProcessing.mFxaa.mLumaThreshold = StringToFloat(lumaThreshold); mPostProcessing.mFxaa.mLumaThresholdMin = StringToFloat(lumaThresholdMin); } else if (line.StartsWith("T ")) { mLevelTitle = lineSub; } else if (line.StartsWith("S ")) { var story = lineSub.Replace('|', '\n'); mLevelStory = story; } else if (line.StartsWith("H ")) { var strings = lineSub.Split(' '); var hutLocation = strings[0].Split(','); var hutRotation = strings[1].Split(','); var hutHp = strings[2]; var x = StringToFloat(hutLocation[0]); var z = StringToFloat(hutLocation[1]); var qX = StringToFloat(hutRotation[0]); var qY = StringToFloat(hutRotation[1]); var qZ = StringToFloat(hutRotation[2]); var qW = StringToFloat(hutRotation[3]); var hp = Convert.ToInt32(hutHp); var vector = new Vector3(x, 0.0f, z); vector.Y = mTerrain.GetHeight(vector); var quaternion = new Quaternion(qX, qY, qZ, qW); var matrix = Matrix.CreateFromQuaternion(quaternion) * Matrix.CreateTranslation(vector); var hut = new Hut(mHutMesh, mLumberjackMesh, mDoubleAxeKillerMesh, mAxeMesh, mSilverback, this, hp, 15.0f, 30.0f, false); hut.Actor.ModelMatrix = matrix; mHuts.Add(hut); if (!mEditMode) { mQuadTree.Insert(hut.Actor, hut.Actor.mBoundingRectangle.GetAxisAlignedRectangle(1)); Add(hut); } else { hut.Actor.IActor = null; Add(hut.Actor); } mCollisionRectangles.Add(hut.Actor.mBoundingRectangle); } else if (line.StartsWith("W ")) { var strings = lineSub.Split(' '); var fogColor = strings[0].Split(','); var fogDistance = strings[1]; mFog.mColor.X = StringToFloat(fogColor[0]); mFog.mColor.Y = StringToFloat(fogColor[1]); mFog.mColor.Z = StringToFloat(fogColor[2]); mFog.mDistance = StringToFloat(fogDistance); } else if (line.StartsWith("N ")) { mNextLevelFilename = lineSub; } else if (line.StartsWith("P ")) { if (mSpawnablePrimatesCount == -1) { mSpawnablePrimatesCount = Convert.ToInt32(lineSub); } } else if (line.StartsWith("I ")) { var strings = lineSub.Split(','); var x = StringToFloat(strings[0]); var z = StringToFloat(strings[1]); var location = new Vector3(x, 0.0f, z); location.Y = mTerrain.GetHeight(location); mInitialSilverbackLocation = location; mSilverback.Actor.ModelMatrix = Matrix.CreateTranslation(location); } } sr.Close(); Add(mTerrain); mVisibilityGraph = new Pathfinding.VisibilityGraph(mCollisionRectangles, new Rectangle(-128, -128, 256, 256), 1.0f, false); Directory.SetCurrentDirectory(currentDirectoryPath); } } catch (FileNotFoundException e) { Console.WriteLine("This file could not be read:"); Console.WriteLine(e.Message); throw; } }