コード例 #1
0
 void Start()
 {
     if (cemetery == null)
     {
         cemetery = GameObject.FindObjectOfType <Cemetery>();
     }
 }
コード例 #2
0
        public IActionResult CreateCemetery([FromBody] Cemetery Cemetery)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            Cemetery.ChangeDate = DateTime.Now;
            Cemetery.CreateDate = DateTime.Now;

            db.Cemeteries.Add(Cemetery);
            db.SaveChanges();

            return(Ok(Cemetery));
        }
コード例 #3
0
            public static void Postfix(Cemetery __instance, bool __result)
            {
                bool enabled = ModMain.settings.enabled.Value && ModMain.settings.graveDiggingSettings.enabled.Value;

                if (__result && enabled)
                {
                    int  meatChance    = (int)ModMain.settings.graveDiggingSettings.spawnMeatOnBurialChance.Value;
                    bool burialHasMeat = random.Next(0, 100) < meatChance;

                    if (burialHasMeat)
                    {
                        // -0.05f hides the meat under the cemetery, but still accessible by villagers.
                        Vector3 position = __instance.B.Center().xz() + new Vector3(0f, -0.05f, 0f);
                        PlaceResourceAt(FreeResourceType.Pork, position);
                    }
                }
            }
コード例 #4
0
            public static void Prefix(Villager __instance, FreeResource resource)
            {
                bool enabled = ModMain.settings.enabled.Value && ModMain.settings.graveDiggingSettings.enabled.Value;
                bool removeGraveAfterDigging = ModMain.settings.graveDiggingSettings.removeGraveAfterDigging.Value;

                if (resource.type == FreeResourceType.Pork && enabled && removeGraveAfterDigging)
                {
                    Vector3 position = resource.transform.position;
                    int     x        = (int)position.x;
                    int     z        = (int)position.z;
                    if (Cemetery.IsCemetery(x, z))
                    {
                        // Refer to Cemetery::IsCemetery.
                        Building building = World.inst.GetCellData(x, z).StructureFindByCategory(World.cemeteryHash);
                        Cemetery cemetery = building.GetComponentInParent <Cemetery>();
                        RemoveRandomGraveFromCemetery(cemetery);
                    }
                }
            }
コード例 #5
0
        public ActionResult CemeteryUpdateEntryToForm(Guid ObjId)
        {
            var      cemeteryInfo = db.Cemeteries.Where(s => s.ObjId == ObjId).FirstOrDefault();
            Cemetery model        = new Cemetery();

            ViewData["SpaceFeatures"] = GetSpaceFeatures();

            if (cemeteryInfo == null)
            {
                return(PartialView("CreateCemeteryEditPartial", model));
            }

            if (cemeteryInfo != null)
            {
                return(PartialView("CreateCemeteryEditPartial", cemeteryInfo));
            }

            return(null);
        }
コード例 #6
0
        public IActionResult UpdateCemetery([FromBody] Cemetery Cemetery)
        {
            // validation
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            // check existing
            if (!db.Cemeteries.Any(pers => pers.Id == Cemetery.Id))
            {
                return(NotFound(Cemetery));
            }

            Cemetery.ChangeDate = DateTime.Now;
            db.Cemeteries.Update(Cemetery);
            db.SaveChanges();

            return(Ok(Cemetery));
        }
コード例 #7
0
        public ActionResult CemeteryEdit(Cemetery item)
        {
            var model  = db.Cemeteries;
            var exists = model.Where(c => c.ObjId == item.ObjId).SingleOrDefault();

            if (exists == null)
            {
                model.Add(item);
                db.SaveChanges();
            }
            if (exists != null)
            {
                this.UpdateModel(exists);
                // model.Attach(userRole);
                db.SaveChanges();
            }
            var BurialRecords = db.Cemeteries.ToList();

            // DXCOMMENT: Pass a data model for GridView in the PartialView method's second parameter
            return(PartialView("GridViewPartialView", BurialRecords));
        }
コード例 #8
0
        private static void RemoveRandomGraveFromCemetery(Cemetery cemetery)
        {
            // Harmony Traverse for accessing private fields.
            // For reference:
            // https://harmony.pardeike.net/articles/utilities.html
            // https://github.com/pardeike/Harmony/issues/289
            Traverse gravesDataTraverse           = Traverse.Create(cemetery).Field("gravesData");
            Traverse gravesRenderInstanceTraverse = Traverse.Create(cemetery).Field("gravesRenderInstance");

            GraveData[]      gravesData           = gravesDataTraverse.GetValue <GraveData[]>();
            RenderInstance[] gravesRenderInstance = gravesRenderInstanceTraverse.GetValue <RenderInstance[]>();

            // Select random grave to remove.
            int totalGraves = gravesData.Length;
            int graveIndex  = random.Next(0, totalGraves);

            if (!gravesData[graveIndex].occupied)
            {
                for (graveIndex = 0; graveIndex < totalGraves; graveIndex++)
                {
                    if (gravesData[graveIndex].occupied)
                    {
                        break;
                    }
                }
            }

            // If graveIndex is equal to totalGraves, there are no free graves.
            if (graveIndex < totalGraves)
            {
                // Refer to Cemetery::Tick.
                gravesRenderInstance[graveIndex].Visible = false;
                gravesData[graveIndex].occupied          = false;
                cemetery.UpdateOpenSlotStatus();
            }
        }
コード例 #9
0
ファイル: Ant.cs プロジェクト: loophac/a-i-nts
        protected virtual void CheckState()
        {
            //refresh state to take new variables state
            ChangeState(state);

            switch (state)
            {
                case AntState.lookForFood:
                    if (food != null)
                    {
                        ChangeState(AntState.goToFood);
                    }
                    break;
                case AntState.goToFood:
                    if (food.Amount == 0 && Vector2.Distance(foodPosition, Position) < ConstantsHolder.Singleton.Vision)
                    {
                        food = null;
                        ChangeState(AntState.lookForFood);
                        break;
                    }
                    if (Vector2.Distance(foodPosition, Position) < ConstantsHolder.Singleton.EatingRadius)
                    {
                        foodCarried = ConstantsHolder.Singleton.CarryMax;
                        food.Amount -= ConstantsHolder.Singleton.CarryMax;
                        ChangeState(AntState.bringBackFood);
                    }
                    break;
                case AntState.bringBackFood:
                    if (Vector2.Distance(AntHill.Position, Position) < ConstantsHolder.Singleton.EatingRadius)
                    {
                        game.AntHill.Food += foodCarried;
                        foodCarried = 0;
                        ChangeState(AntState.goToFood);
                    }
                    break;
                case AntState.transportCorpse:
                    cadaver.Position = position;
                    //if the ant don't know a cemetery it will just put the corpse at a sanitary distance of the anthill
                    if (cemeteryBest == null)
                    {
                        if (Vector2.Distance(position, antHill.Position) > ConstantsHolder.Singleton.SainityDistance)
                        {
                            //double tap!
                            cadaver.Kill();
                            if (leftToClean > 0)
                            {
                                ChangeState(AntState.backToClean);
                            }
                            else
                            {
                                ChangeState(previousState);
                            }
                        }
                    }
                    else
                    {
                        // the ant reaches the biggest known cemetery it put the cadaver in the cemetery
                        if (Vector2.Distance(goal, Position) < ConstantsHolder.Singleton.EatingRadius)
                        {
                            //if the best known have desapeared the ant just put the corpse at a sanitary distance from the anthill
                            if (cemeteryBest.Count == 0)
                            {
                                cemeteryBest = null;
                                //double tap!
                                cadaver.Kill();
                            }
                            else
                            {
                                cemeteryBest.Add(cadaver);
                            }
                            cadaver = null;
                            //go back to clean the previous cemetery if it is not known as empty
                            if (leftToClean > 0)
                            {
                                ChangeState(AntState.backToClean);
                            }
                            else
                            {
                                ChangeState(previousState);
                            }
                            break;
                        }
                    }

                    break;
                case AntState.goToCorpse:
                    if (Vector2.Distance(goal, Position) < ConstantsHolder.Singleton.EatingRadius)
                    {
                        //take a cadaver in a cemetery when it reach it
                        if (cemeteryToClean.Contains(cadaver))
                        {
                            cemeteryToClean.Remove(cadaver);
                            leftToClean = cemeteryToClean.Count;
                            //if taking the corpse clean the cemetery it will be destroyed
                            if (cemeteryToClean.Count == 0)
                            {
                                game.Cemeteries.Remove(cemeteryToClean);
                                cemeteryToClean = null;

                            }

                            ChangeState(AntState.transportCorpse);
                        }
                        //if the corpse have been taken by an other ant, it return to normal activity
                        else
                        {
                            ChangeState(previousState);
                        }

                    }
                    break;
                //go back the previous cemetery to clean it
                case AntState.backToClean:
                    //if the cemetery is empty the ant remove it and go back to its activity
                    //if it's full the ant will automatically change state to goforCorpse from the cemetery scan in the update function
                    if (Vector2.Distance(goal, Position) < ConstantsHolder.Singleton.Vision)
                    {
                        if (cemeteryToClean == null || cemeteryToClean.Count == 0)
                        {
                            leftToClean = 0;
                            cemeteryToClean = null;
                            if (previousState == AntState.backToClean)
                            {
                                previousState = AntState.lookForFood;
                            }
                            ChangeState(previousState);
                        }
                    }
                    break;
            }
        }
コード例 #10
0
ファイル: Ant.cs プロジェクト: loophac/a-i-nts
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            //the ant have a certain probability to die each frame
            double ran = game.Random.NextDouble();
            if (ran < 0.5f / ConstantsHolder.Singleton.HalfLife)
            {
                Kill();
            }
            CheckState();
            if (Vector2.Distance(AntHill.Position, Position) < ConstantsHolder.Singleton.EatingRadius)
            {
                if (AntHill.Food >= 0)
                {
                    AntHill.Food -= Hungry;
                    Hungry = 0;
                }
            }
            if (Hungry > ConstantsHolder.Singleton.Starvation)
            {
                Kill();
            }

            //find closest food point
            foreach (Food possibleFood in game.Foods)
            {
                if (Vector2.Distance(possibleFood.Position, Position) < ConstantsHolder.Singleton.Vision
                    && (food == null || Vector2.Distance(possibleFood.Position, AntHill.Position) < Vector2.Distance(food.Position, AntHill.Position)))
                {
                    food = possibleFood;
                    foodPosition = possibleFood.Position;
                    if (state == AntState.goToFood)
                    {
                        goal = food.Position;
                    }
                }
            }

            //find bigest cemetery around
            for (int i = 0; i < game.Cemeteries.Count; i++)
            {
                Cemetery possibleCemetery = game.Cemeteries[i];
                //within view range
                if (Vector2.Distance(possibleCemetery.Position, Position) < ConstantsHolder.Singleton.Vision
                    && possibleCemetery.Count!=0)
                {
                    //find bigest cemetery
                    if ( Vector2.Distance(possibleCemetery.Position,antHill.Position)>=ConstantsHolder.Singleton.SainityDistance
                        && (cemeteryBest == null || possibleCemetery.Count > cemeterySmell))
                    {
                        //if the ant had a previous best cemetery, it decided to move it in the new one
                        bool needToClean = false;
                        if (cemeteryBest != null
                            && cemeteryBest != possibleCemetery
                            && state != AntState.goToCorpse
                            && state != AntState.transportCorpse)
                        {
                            cemeteryToClean = cemeteryBest;
                            cemeteryToCleanPos = cemeteryToClean.Position;
                            previousState = state;
                            needToClean = true;
                        }
                        //update the biggest known cemetery
                        cemeteryBest = possibleCemetery;
                        cemeterySmell = possibleCemetery.Count;
                        if (state == AntState.transportCorpse)
                        {
                            goal = possibleCemetery.Position;
                            goalLover = ConstantsHolder.Singleton.TransportGoal;
                        }
                        //start to clean the old cemetery
                        if (needToClean)
                        {
                            ChangeState(AntState.backToClean);
                        }
                    }
                    ////with a decent distance to the hill
                    //if (Vector2.Distance(possibleCemetery.Position, antHill.Position) >= ConstantsHolder.Singleton.SainityDistance
                    //    && (cemeteryBest == null || possibleCemetery.Count > cemeterySmell))
                    //{
                    //    bool needToClean = false;
                    //    if (cemeteryBest != null
                    //        && cemeteryBest != possibleCemetery
                    //        && state != AntState.goToCorpse
                    //        && state != AntState.transportCorpse)
                    //    {
                    //        cemeteryToClean = cemeteryBest;
                    //        cemeteryToCleanPos = cemeteryToClean.Position;
                    //        previousState = state;
                    //        needToClean = true;
                    //    }
                    //    cemeteryBest = possibleCemetery;
                    //    cemeterySmell = possibleCemetery.Count;
                    //    if (state == AntState.transportCorpse)
                    //    {
                    //        goal = possibleCemetery.Position;
                    //        goalLover = ConstantsHolder.Singleton.TransportGoal;
                    //    }
                    //    if (needToClean)
                    //    {
                    //        ChangeState(AntState.backToClean);
                    //    }
                    //}

                    //Update the size of the biggest known cemetery
                    if (possibleCemetery == cemeteryBest)
                    {
                        cemeterySmell = possibleCemetery.Count;
                    }
                    //if the cemetery seen is not the biggest the ant start to clean it
                    //if the ant is not already carrying a corpse a going to a corpse
                    else if (state != AntState.goToCorpse && state != AntState.transportCorpse  )
                    {
                        cadaver = possibleCemetery.Last();
                        //handle a little bug that sometime the cemetery have one null cadaver instead of nothing
                        //it would be maybe cleaner to prevent that
                        if (cadaver != null)
                        {
                            cemeteryToClean = possibleCemetery;
                            cemeteryToCleanPos = cemeteryToClean.Position;
                            previousState = state;
                            //remember the size to know if there is a need to come back to clean
                            leftToClean = cemeteryToClean.Count;
                            ChangeState(AntState.goToCorpse);
                        }
                        else
                        {
                            //we don't keep empty cemeteries
                            game.Cemeteries.Remove(possibleCemetery);
                            if (state == AntState.backToClean)
                            {
                                cemeteryToClean = null;
                                ChangeState(previousState);
                            }
                        }
                    }
                }
            }

            this.previousPosition = this.position;
        }
コード例 #11
0
 public CemeteryShort(Cemetery cemetery)
 {
     Id   = cemetery.Id;
     Name = cemetery.Name;
 }
コード例 #12
0
 //---------------------------------------------------------------------------------------------------------
 /// <summary>
 /// Объединение данных
 /// </summary>
 /// <param name="special_infrastructure">Список территорий специального назначения</param>
 //---------------------------------------------------------------------------------------------------------
 public void Union(CSpecialInfrastructure special_infrastructure)
 {
     Cemetery.Union(special_infrastructure.Cemetery);
     Landfill.Union(special_infrastructure.Landfill);
     CattleCemetery.Union(special_infrastructure.CattleCemetery);
 }
コード例 #13
0
        public static void Initialize(CemeteryContext context)
        {
            if (context.Roles.Any())
            {
                return;
            }

            var role = new AspNetRole
            {
                Name = "admin"
            };

            context.Roles.Add(role);
            context.SaveChanges();

            var user = new AspNetUser
            {
                UserName     = "******",
                PasswordHash = "demo",
                Role         = role
            };

            context.Users.Add(user);
            context.SaveChanges();

            var cem = new Cemetery
            {
                Address    = "Воронино посёлок, 1",
                Name       = "Кладбище Воронино",
                CreateDate = DateTime.Now,
                ChangeDate = DateTime.Now,
                imgs       = new string[] { "assets/images/img.jpg", "assets/images/img1.jpg", "assets/images/img2.jpg" }
            };

            context.Cemeteries.Add(cem);
            context.SaveChanges();

            var sector = new Sector
            {
                SectorName = "35",
                CreateDate = DateTime.Now,
                ChangeDate = DateTime.Now,
                Cemetery   = cem,
                Imgs       = new string[] { "assets/images/img.jpg", "assets/images/img1.jpg", "assets/images/img2.jpg" }
            };

            context.Sectors.Add(sector);
            context.SaveChanges();

            for (int i = 1; i <= 224; i++)
            {
                var place = new Place
                {
                    CreateDate = DateTime.Now,
                    ChangeDate = DateTime.Now,
                    Sector     = sector,
                    Number     = i,
                    Status     = "вменяемое",
                    PlaceType  = "хозяйственное",
                    SoilType   = "глина твёрдая",
                    Imgs       = new string[] { "assets/images/img.jpg", "assets/images/img1.jpg", "assets/images/img2.jpg" }
                };

                context.Places.Add(place);
            }
            context.SaveChanges();

            var textData = File.ReadAllLines(@"cemetery_data.txt");

            foreach (var line in textData)
            {
                var data = line.Split(" ");

                // deathdate
                var      ddstr = data[5].Split(".");
                DateTime dd    = new DateTime(
                    int.Parse(ddstr[2]),
                    int.Parse(ddstr[1]),
                    int.Parse(ddstr[0])
                    );
                // birthdate
                var      bdstr = data[4].Split(".");
                DateTime bd    = new DateTime(
                    int.Parse(bdstr[2]),
                    int.Parse(bdstr[1]),
                    int.Parse(bdstr[0])
                    );

                var burial = new Burial
                {
                    // FullName = data[1] + " " + data[2] + " " + data[3],
                    Surname    = data[1],
                    Name       = data[2],
                    Patronymic = data[3],
                    DeathDate  = dd,
                    BirthDate  = bd,
                    BurialDate = bd,
                    CreateDate = DateTime.Now,
                    FuneralUrn = "нет",
                    Place      = context.Places.FirstOrDefault(p => p.Number == int.Parse(data[0])),
                    imgs       = new string[] { "assets/images/img.jpg", "assets/images/img1.jpg", "assets/images/img2.jpg" }
                };
                context.Burials.Add(burial);

                var other = new Other()
                {
                    PersonKey           = burial.Id,
                    GraveDepth          = 2.123,
                    DateOfReference     = bd,
                    RegistrationAddress = "Томский ЗАГС",
                    SoilType            = "хорошее",
                    CertificateNumber   = "СВ-123456",
                    ArchivedNumber      = (new Random()).Next(10000),
                };
                context.Others.Add(other);

                var relat = new Relative()
                {
                    RelativeFullName = "Chelpa", Address = "Baker st., 7", Contacts = "89002281488", PersonKey = burial.Id
                };
                context.Relatives.Add(relat);
            }
            context.SaveChanges();
        }