示例#1
0
        /// <summary>
        /// Find defined things in reach and return an IEnumerable
        /// </summary>
        /// <param name="position">The starting position</param>
        /// <returns></returns>
        public static IEnumerable <Thing> FindThingsInRoom(IntVec3 position)
        {
            Room room = RoomQuery.RoomAt(position);

            // LINQ version
            return(Find.ListerThings.AllThings.Where(t => room == RoomQuery.RoomAt(t.Position)));
        }
        public override void SpawnSetup()
        {
            base.SpawnSetup();

            GetTextures();

            _txtMinus = Prefs.TemperatureMode == TemperatureDisplayMode.Celsius ? "-1°C" : "-2°F";
            _txtPlus  = Prefs.TemperatureMode == TemperatureDisplayMode.Celsius ? "1°C" : "2°F";

            _txtMinTempMinus = "MinTempMinus".Translate();
            _txtMinTempPlus  = "MinTempPlus".Translate();
            _txtMaxTempMinus = "MaxTempMinus".Translate();
            _txtMaxTempPlus  = "MaxTempPlus".Translate();

            _txtWatt          = "Watt".Translate();
            _txtStatus        = "Status".Translate();
            _txtStatusWaiting = "StatusWaiting".Translate();
            _txtStatusHeating = "StatusHeating".Translate();
            _txtStatusCooling = "StatusCooling".Translate();
            _txtStatusOutdoor = "StatusOutdoor".Translate();

            _txtMinComfortTemp = "MinComfortTemp".Translate();
            _txtMaxComfortTemp = "MaxComfortTemp".Translate();


            _txtPowerNotConnected        = "PowerNotConnected".Translate();
            _txtPowerNeeded              = "PowerNeeded".Translate();
            _txtPowerConnectedRateStored = "PowerConnectedRateStored".Translate();

            _powerTrader = GetComp <CompPowerTrader>();

            _room = RoomQuery.RoomAt(Position);
        }
示例#3
0
        /// <summary>
        /// Find defined things in reach and return an IEnumerable
        /// </summary>
        /// <param name="position">The starting position</param>
        /// <param name="room">The containing room</param>
        /// <param name="distance">The maximal distance to find targets</param>
        /// <returns></returns>
        public static IEnumerable <Thing> FindThingsInRoom(IntVec3 position, float distance)
        {
            Room room = RoomQuery.RoomAt(position);

            // LINQ version
            return(Find.ListerThings.AllThings.Where(t => t.Position.InHorDistOf(position, distance) && room == RoomQuery.RoomAt(t.Position)));
        }
        protected override ThoughtState CurrentStateInternal(Pawn p)
        {
            // TODO: There's gotta be a better way of doin' this!
            if (!AncestorUtils.IsAncestor(p))
            {
                return(ThoughtState.Inactive);
            }

            var shrine = AncestorUtils.GetMapComponent().CurrentSpawner;

            if (shrine == null)
            {
                return(ThoughtState.ActiveAtStage(1));
            }

            // HACK ALERT! Change Shrines to have an Interaction cell, and use that instead of a random one!
            var room = RoomQuery.RoomAtFast(shrine.RandomAdjacentCellCardinal());

            if (room == null)
            {
                return(ThoughtState.ActiveAtStage(1));
            }
            else if (room.Role != shrineRoomDef)
            {
                return(ThoughtState.ActiveAtStage(1));
            }
            else
            {
                return(ThoughtState.Inactive);
            }
        }
示例#5
0
文件: AFS.cs 项目: DAOWAce/Clutter
        private IEnumerable <Thing> FindFireInRoomAndDistance(IntVec3 position, float distance)
        {
            Room room = RoomQuery.RoomAt(position);

            if (room == null)
            {
                IEnumerable <IntVec3> founds = GenAdj.AdjacentSquares8WayAndInside(position);
                foreach (IntVec3 found in founds)
                {
                    if (RoomQuery.RoomAt(found) != null)
                    {
                        room = RoomQuery.RoomAt(found);
                        break;
                    }
                }
            }

            IEnumerable <Thing> fires = Find.ListerThings.ThingsOfDef(ThingDefOf.Fire);

            if (fires == null)
            {
                return(fires);
            }
            // Correction here: (room == room OR room == null) && within distance
            else
            {
                return(fires.Where <Thing>(t => (room == RoomQuery.RoomAt(t.Position) || RoomQuery.RoomAt(t.Position) == null) &&
                                           t.Position.WithinHorizontalDistanceOf(position, distance)));
            }
        }
示例#6
0
        public ActionResult <List <CassandraRoom> > GetListUnoccupied([FromBody] Hotel hotel)
        {
            Console.WriteLine("Get Unoccupied in " + hotel.name);
            List <CassandraRoom> result = RoomQuery.ToOccupy(hotel);

            return(result);
        }
示例#7
0
 /// <summary>
 /// Find all pawns in room within a certain distance and return an IEnumerable
 /// </summary>
 /// <param name="positon">The source position</param>
 /// <param name="distance">The maximal distance</param>
 /// <returns></returns>
 public static IEnumerable <Pawn> FindAllPawnsInRoom(IntVec3 position, Room room, float distance)
 {
     // LINQ version
     return(Find.MapPawns.AllPawnsSpawned.Where(p => !p.InContainer &&
                                                (RoomQuery.RoomAt(p.Position) == room) &&
                                                (p.Position.InHorDistOf(position, distance))));
 }
        public override void TickRare()
        {
            base.TickRare();

            _txtMinus = Prefs.TemperatureMode == TemperatureDisplayMode.Celsius ? "-1°C" : "-2°F";
            _txtPlus  = Prefs.TemperatureMode == TemperatureDisplayMode.Celsius ? "1°C" : "2°F";

            _room = RoomQuery.RoomAt(Position);

            if (!_powerTrader.PowerOn || _room == null || _room.UsesOutdoorTemperature)
            {
                if (_room != null && _room.UsesOutdoorTemperature)
                {
                    WorkStatus = Status.Outdoor;
                }
                _powerTrader.PowerOutput = 0;
                return;
            }

            var currentTemp = _room.Temperature;

            if (currentTemp >= _minComfortTemp && currentTemp <= _maxComfortTemp)
            {
                WorkStatus = Status.Waiting;
                _powerTrader.PowerOutput = -1.0f;
                return;
            }

            var diffTemp  = 0.0f;
            var powerMod  = 1.1f;
            var energyMul = 1.0f;

            if (currentTemp < _minComfortTemp)
            {
                WorkStatus = Status.Heating;
                diffTemp   = _minComfortTemp - currentTemp;
            }

            if (currentTemp > _maxComfortTemp)
            {
                WorkStatus = Status.Cooling;
                diffTemp   = _maxComfortTemp - currentTemp;
                powerMod   = 1.6f;
            }

            if (Mathf.Abs(diffTemp) < 3)
            {
                energyMul += 0.5f;
            }

            var efficiencyLoss = EfficiencyLossPerDegreeDifference * Mathf.Abs(diffTemp);
            var enegyLimit     = diffTemp * _room.CellCount * energyMul * 0.3333f;
            var needPower      = Mathf.Abs(enegyLimit * (powerMod + efficiencyLoss));

            _powerTrader.PowerOutput = -needPower;
            ChangeTemp(enegyLimit);
        }
示例#9
0
        public ActionResult Vacant()
        {
            var query = new RoomQuery {
                IsVacant = true
            };

            var vacantRooms = _unitOfWork.Rooms.GetRooms(query);

            var viewModel = Mapper.Map <IEnumerable <Room>, List <RoomsListViewModel> >(vacantRooms);

            return(View(viewModel));
        }
示例#10
0
        public IHttpActionResult GetRooms(int roomType)
        {
            var query = new RoomQuery {
                RoomType = roomType, IsVacant = true
            };

            var vacantRooms = _unitOfWork.Rooms.GetRooms(query);

            var dto = Mapper.Map <IEnumerable <Room>, List <RoomDto> >(vacantRooms);

            return(Ok(dto));
        }
 public async Task <IEnumerable <Room> > GetRooms(RoomQuery roomQuery)
 {
     try
     {
         return(await repository.GetRooms(roomQuery));
     }
     catch (Exception e)
     {
         logger.LogError(e.Message);
         return(null);
     }
 }
示例#12
0
        /// <summary>
        /// Search for pawn in the room
        /// </summary>
        /// <returns></returns>
        private bool SearchForPawnInRoom()
        {
            IEnumerable <Pawn> pawns;

            if (!pawnSearchModeDistanceActive)
            {
                pawns = Radar.FindAllPawnsInRoom(RoomQuery.RoomAt(Position));
            }
            else
            {
                pawns = Radar.FindAllPawns(this.Position, radarDistancePawn);
            }

            return(pawns.Count() > 0);
        }
示例#13
0
        public static List <Guid> AddRoom(string roomShortName, string roomLongName)
        {
            var query        = new RoomQuery();
            var sessionToken = query.Login(TestDefaults.Default.TestUser,
                                           TestDefaults.Default.TestUserPassword,
                                           TestDefaults.Default.SchoolID,
                                           TestDefaults.Default.TenantId.ToString(CultureInfo.InvariantCulture),
                                           Configuration.GetSutUrl() + TestDefaults.Default.ApplicationServerPath,
                                           Configuration.GetSutUrl() + TestDefaults.Default.SecurityServerPath);

            //Retrieved collection of Staff Records
            DataEntityCollectionDTO staffCollection = query.RetrieveEntityByNameQuery("SIMS8SchoolRoomSearchQuery", new Dictionary <string, object>(), sessionToken);

            return(null);
        }
示例#14
0
        public override void DrawGhost(ThingDef def, IntVec3 center, Rot4 rot)
        {
            foreach (
                var unit in
                Find.ListerBuildings.AllBuildingsColonistOfClass <Building_ClimateControl>()
                .Where(unit => unit.Position == center))
            {
                _climateControl = unit;
                break;
            }
            var room = RoomQuery.RoomAt(center);

            if (room == null || room.UsesOutdoorTemperature)
            {
                return;
            }

            if (_climateControl == null)
            {
                return;
            }
            var status = _climateControl.WorkStatus;

            var color = Color.white;

            switch (status)
            {
            case Status.Waiting:
                color = new Color(1f, 0.7f, 0.0f, 0.5f);
                break;

            case Status.Heating:
                color = GenTemperature.ColorRoomHot;
                break;

            case Status.Cooling:
                color = GenTemperature.ColorRoomCold;
                break;

            case Status.Outdoor:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            GenDraw.DrawFieldEdges(room.Cells.ToList(), color);
        }
示例#15
0
        public IEnumerable <Room> GetRooms(RoomQuery roomQuery)
        {
            var query = _context.Rooms.AsQueryable();

            if (roomQuery != null && roomQuery.RoomType.HasValue)
            {
                query = query.Where(c => (int)c.Type == roomQuery.RoomType.Value);
            }

            if (roomQuery != null && roomQuery.IsVacant.HasValue && roomQuery.IsVacant.Value)
            {
                query = query.Where(i => !i.IsCurrentlyRented);
            }

            return(query.ToList());
        }
示例#16
0
        // Token: 0x06000DC4 RID: 3524 RVA: 0x000456A8 File Offset: 0x000438A8
        internal static void _ObserveSurroundingThings(this PawnObserver _this)
        {
            Pawn pawn = _this.GetPawn();

            if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Sight))
            {
                return;
            }
            Room room = RoomQuery.RoomAt(pawn.Position);
            int  num  = 0;

            while ((float)num < 100f)
            {
                IntVec3 c = pawn.Position + GenRadial.RadialPattern[num];
                if (c.InBounds())
                {
                    if (RoomQuery.RoomAt(c) == room)
                    {
                        List <Thing> thingList = c.GetThingList();
                        for (int i = 0; i < thingList.Count; i++)
                        {
                            IThoughtGiver thoughtGiver = thingList[i] as IThoughtGiver;
                            if (thoughtGiver != null)
                            {
                                Thought_Memory thought_Memory = thoughtGiver.GiveObservedThought();
                                if (thought_Memory != null)
                                {
                                    if (thought_Memory.def == ThoughtDefOf.ObservedLayingCorpse)
                                    {
                                        if (!pawn.story.traits.HasTrait(TraitDefOfPsychology.BleedingHeart) && !pawn.story.traits.HasTrait(TraitDefOf.Psychopath) && !pawn.story.traits.HasTrait(TraitDefOf.Bloodlust))
                                        {
                                            if (((pawn.GetHashCode() ^ (GenDate.DayOfYear + GenDate.CurrentYear + (int)(GenDate.CurrentDayPercent * 5) * 60) * 391) % 1000) == 0)
                                            {
                                                pawn.story.traits.GainTrait(new Trait(TraitDefOfPsychology.Desensitized));
                                                pawn.needs.mood.thoughts.memories.TryGainMemoryThought(ThoughtDefOfPsychology.RecentlyDesensitized, (Pawn)null);
                                            }
                                        }
                                    }
                                    pawn.needs.mood.thoughts.memories.TryGainMemoryThought(thought_Memory, null);
                                }
                            }
                        }
                    }
                }
                num++;
            }
        }
示例#17
0
        public async Task <QueryResult <Room> > GetRooms(RoomQuery queryObj)
        {
            var result = new QueryResult <Room>();

            var query = context.Rooms
                        .Include(rt => rt.RoomType)
                        .Include(rs => rs.RoomState)
                        .Include(b => b.CurrentBook)
                        .ThenInclude(b => b.Guests)
                        .ThenInclude(g => g.Guest)
                        .Include(rb => rb.Beds)
                        .ThenInclude(b => b.Bed)
                        .AsQueryable();

            if (queryObj.RoomTypeId.HasValue)
            {
                query = query.Where(v => v.RoomType.Id == queryObj.RoomTypeId.Value);
            }

            if (queryObj.RoomStateId.HasValue)
            {
                query = query.Where(v => v.RoomState.Id == queryObj.RoomStateId.Value);
            }

            if (queryObj.FloorNumber.HasValue)
            {
                query = query.Where(v => v.FloorNumber == queryObj.FloorNumber.Value);
            }

            var columnsMap = new Dictionary <string, Expression <Func <Room, object> > >()
            {
                ["roomType"]    = v => v.RoomType.Id,
                ["roomState"]   = v => v.RoomState.Id,
                ["floorNumber"] = v => v.FloorNumber,
                ["doorNumber"]  = v => v.DoorNumber
            };

            query = query.ApplyOrdering(queryObj, columnsMap);

            result.TotalItems = await query.CountAsync();

            query = query.ApplyPaging(queryObj);

            result.Items = await query.ToListAsync();

            return(result);
        }
示例#18
0
        public ActionResult Index()
        {
            var vacantQuery = new RoomQuery {
                IsVacant = true
            };
            var rentedQuery = new RoomQuery {
                IsVacant = false
            };

            var roomsChartViewModel = new RoomsChartViewModel
            {
                VacantRoomsCount = _unitOfWork.Rooms.GetRooms(vacantQuery).Count(),
                RentedRoomsCount = _unitOfWork.Rooms.GetRooms(rentedQuery).Count()
            };

            return(View(roomsChartViewModel));
        }
示例#19
0
        private static bool FoodAvailableInRoomTo(Pawn prisoner)
        {
            if (prisoner.carryTracker.CarriedThing != null && WorkGiver_Warden_DeliverFood.NutritionAvailableForFrom(prisoner, prisoner.carryTracker.CarriedThing) > 0f)
            {
                return(true);
            }
            float num  = 0f;
            float num2 = 0f;
            Room  room = RoomQuery.RoomAt(prisoner);

            if (room == null)
            {
                return(false);
            }
            for (int i = 0; i < room.RegionCount; i++)
            {
                Region       region = room.Regions[i];
                List <Thing> list   = region.ListerThings.ThingsInGroup(ThingRequestGroup.FoodSourceNotPlantOrTree);
                for (int j = 0; j < list.Count; j++)
                {
                    Thing thing = list[j];
                    // --------- mod ------------
                    if ((thing.def == ThingDefOf.NutrientPasteDispenser & prisoner.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) || thing.def.ingestible.preferability > FoodPreferability.NeverForNutrition)
                    {
                        num2 += WorkGiver_Warden_DeliverFood.NutritionAvailableForFrom(prisoner, thing);
                    }
                    // --------- mod end ------------
                }
                //if (region.ListerThings.ThingsOfDef(ThingDefOf.NutrientPasteDispenser).Any<Thing>() && prisoner.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
                //{
                //	return true;
                //}
                List <Thing> list2 = region.ListerThings.ThingsInGroup(ThingRequestGroup.Pawn);
                for (int k = 0; k < list2.Count; k++)
                {
                    Pawn pawn = list2[k] as Pawn;
                    if (pawn.IsPrisonerOfColony && pawn.needs.food.CurLevelPercentage < pawn.needs.food.PercentageThreshHungry + 0.02f && (pawn.carryTracker.CarriedThing == null || !pawn.RaceProps.WillAutomaticallyEat(pawn.carryTracker.CarriedThing)))
                    {
                        num += pawn.needs.food.NutritionWanted;
                    }
                }
            }

            return(num2 + 0.5f >= num);
        }
示例#20
0
        public async Task <QueryResult <Room> > GetRooms(RoomQuery queryObj)
        {
            var result = new QueryResult <Room>();

            var query = SchedulingDbContext.Rooms
                        .Include(r => r.Building)
                        .Include(r => r.Types)
                        .ThenInclude(t => t.Type)
                        .AsQueryable();

            query = query.ApplyRoomFilter(queryObj);

            result.TotalItems = await query.CountAsync();

            result.Items = await query.ToListAsync();

            return(result);
        }
示例#21
0
        private static RoomAndScore[] GetRooms(Pawn searcher, Map map)
        {
            var rooms = new HashSet <Room>();

            foreach (var building in map.listerBuildings.allBuildingsColonist)
            {
                var room = RoomQuery.RoomAtFast(building.Position, map);
                // Only check one cell per room - otherwise this may be way too expensive (e.g. far away room, when colony is closed off)
                if (room != null && room.CellCount > 8 && !room.PsychologicallyOutdoors && map.reachability.CanReachColony(room.Cells.First(cell => cell.Walkable(map))))
                {
                    rooms.Add(room);
                }
            }
            return
                (rooms.Select(room => new RoomAndScore {
                room = room, score = RoomScore(room, searcher)
            })
                 .OrderByDescending(r => r.score)
                 .ToArray());
        }
        public static IQueryable <Room> ApplyFiltering(this IQueryable <Room> query, RoomQuery queryObj)
        {
            // This filter return a bool is for that I do the else sentence

            if (queryObj.IsFurnished.HasValue && queryObj.IsFurnished == 1)
            {
                query = query.Where(r => r.IsFurnished);
            }
            if (queryObj.IsFurnished.HasValue && queryObj.IsFurnished == 0)
            {
                query = query.Where(r => r.IsFurnished == false);
            }

            if (queryObj.Pet != null)
            {
                query = query.Where(r => r.Pet == queryObj.Pet);
            }

            //  ...

            return(query);
        }
示例#23
0
 /// <summary>
 /// Find all pawns in room and return an IEnumerable
 /// </summary>
 /// <param name="room">Find in which room</param>
 /// <returns></returns>
 public static IEnumerable <Pawn> FindAllPawnsInRoom(Room room)
 {
     // LINQ version
     return(Find.MapPawns.AllPawnsSpawned.Where(p => !p.InContainer && (room == RoomQuery.RoomAt(p.Position))));
 }
示例#24
0
        public ActionResult <List <CassandraRoom> > GetListByHotel([FromBody] Hotel hotel)
        {
            List <CassandraRoom> result = RoomQuery.ByHotel(hotel);

            return(result);
        }
示例#25
0
        public async Task <IActionResult> GetRooms(RoomQuery query)
        {
            var rooms = await unitOfWork.Rooms.GetRooms(query);

            return(Ok(mapper.Map <QueryResult <Room>, QueryResult <RoomResource> >(rooms)));
        }
示例#26
0
 public override void Tick()
 {
     if (pawn.Downed || pawn.Dead || (pawn.pather != null && pawn.pather.WillCollideWithPawnOnNextPathCell()))
     {
         pawn.health.RemoveHediff(this);
         if (pawn.pather != null)
         {
             AlertThief(pawn, pawn.pather.nextCell.GetFirstPawn(pawn.Map));
         }
         else
         {
             AlertThief(pawn, null);
         }
     }
     if (pawn.pather != null && GetLastCell(pawn.pather).GetDoor(pawn.Map) != null)
     {
         GetLastCell(pawn.pather).GetDoor(pawn.Map).StartManualCloseBy(pawn);
     }
     if (pawn.Map != null && lastSpottedTick < Find.TickManager.TicksGame - 250)
     {
         lastSpottedTick = Find.TickManager.TicksGame;
         Room room = RoomQuery.RoomAt(pawn);
         int  num  = 0;
         while (num < 20)
         {
             IntVec3 c = pawn.Position + GenRadial.RadialPattern[num];
             if (c.InBounds(pawn.Map))
             {
                 if (RoomQuery.RoomAt(c, pawn.Map) == room)
                 {
                     List <Thing> thingList = c.GetThingList(pawn.Map);
                     foreach (Thing thing in thingList)
                     {
                         Pawn observer = thing as Pawn;
                         if (observer != null && observer != pawn && observer.Faction != null && observer.Faction.IsPlayer)
                         {
                             float observerSight = observer.health.capacities.GetEfficiency(PawnCapacityDefOf.Sight);
                             observerSight *= 0.805f + (pawn.Map.glowGrid.GameGlowAt(pawn.Position) / 4);
                             if (observer.RaceProps.Animal)
                             {
                                 observerSight *= 0.9f;
                             }
                             observerSight = Math.Min(2f, observerSight);
                             float thiefMoving = pawn.health.capacities.GetEfficiency(PawnCapacityDefOf.Moving);
                             float spotChance  = 0.8f * thiefMoving / observerSight;
                             if (Rand.Value > spotChance)
                             {
                                 pawn.health.RemoveHediff(this);
                                 AlertThief(pawn, observer);
                             }
                         }
                     }
                 }
             }
             num++;
         }
         Thing holding = pawn.carryTracker.CarriedThing;
         if (lastCarried != holding)
         {
             if (lastCarried != null)
             {
                 SetGraphicInt(lastCarried, lastCarriedGraphic);
             }
             if (holding != null)
             {
                 lastCarried        = holding;
                 lastCarriedGraphic = holding.Graphic;
                 SetGraphicInt(lastCarried, new Graphic_Invisible());
             }
         }
     }
 }
        public async Task <IEnumerable <Room> > GetRooms(RoomQuery queryObj)
        {
            var query = context.Rooms
                        .Include(r => r.PropertyType)
                        .Include(r => r.Preference)
                        .Include(r => r.Rules)
                        .ThenInclude(rpr => rpr.PropertyRules)
                        .Include(r => r.PropertyFeatures)
                        .ThenInclude(rpf => rpf.PropertyFeatures)
                        .Include(r => r.RoomFeatures)
                        .ThenInclude(rrf => rrf.RoomFeatures)
                        .Where(x => x.Deleted == false);

            /*Filters Here*/

            query = query.ApplyFiltering(queryObj);

            // This filter return a bool is for that I do the else sentence

            /*
             * if (queryObj.IsFurnished.HasValue && queryObj.IsFurnished == 1)
             *  query = query.Where(r => r.IsFurnished);
             * if (queryObj.IsFurnished.HasValue && queryObj.IsFurnished == 0)
             *  query = query.Where(r => r.IsFurnished == false);
             *
             * if (queryObj.Pet != null)
             *  query = query.Where(r => r.Pet == queryObj.Pet);
             *
             * //  ...
             */

            /*
             * Sorting
             */

            var columnsMap = new Dictionary <string, Expression <Func <Room, object> > >()
            {
                ["isfurnished"] = room => room.IsFurnished,
                ["pet"]         = room => room.Pet
            };

            query = query.ApplySorting(queryObj, columnsMap);

            /*
             * Forma Ampliada de Sorting
             *
             * if (queryObj.SortBy.ToLower() == "isfurnished")
             *  query = queryObj.IsSortAsc
             *      ? query.OrderBy(r => r.IsFurnished)
             *      : query.OrderByDescending(r => r.IsFurnished);
             *
             * if (queryObj.SortBy.ToLower() == "pet")
             *  query = queryObj.IsSortAsc ? query.OrderBy(r => r.Pet) : query.OrderByDescending(r => r.Pet);
             */


            /*
             *  Pagining
             */

            query = query.ApplyPaging(queryObj);

            /*
             * Forma Ampliada de Paging
             *
             * if (queryObj.Page <= 0)
             * queryObj.Page = 1;
             * if (queryObj.PageSize <= 0)
             * queryObj.PageSize = 10;
             * query = query.Skip((queryObj.Page - 1) * queryObj.PageSize).Take(queryObj.PageSize);
             */


            return(await query.ToListAsync());
        }
示例#28
0
        private void FindAdjacentRooms()
        {
            adjacentRooms.Clear();
            if (room.UsesOutdoorTemperature)
            {
                return;
            }
            Map            visibleMap = Find.VisibleMap;
            List <IntVec3> cells      = new List <IntVec3>();

            foreach (IntVec3 current in room.Cells)
            {
                cells.Add(current);
            }

            if (fieldGrid == null)
            {
                fieldGrid = new BoolGrid(visibleMap);
            }
            else
            {
                fieldGrid.ClearAndResizeTo(visibleMap);
            }

            int x     = visibleMap.Size.x;
            int z     = visibleMap.Size.z;
            int count = cells.Count;

            for (int i = 0; i < count; i++)
            {
                if (cells[i].InBounds(visibleMap))
                {
                    fieldGrid[cells[i].x, cells[i].z] = true;
                }
            }
            for (int j = 0; j < count; j++)
            {
                IntVec3 c = cells[j];
                if (c.InBounds(visibleMap))
                {
                    if (c.z < z - 1 && !fieldGrid[c.x, c.z + 1])
                    {
                        var door = Find.VisibleMap.thingGrid.ThingsAt(new IntVec3(c.x, c.y, c.z + 1)).ToList().Find(s => s.def.defName == "Door");
                        if (door != null)
                        {
                            adjacentRooms.Add(RoomQuery.RoomAt(new IntVec3(c.x, c.y, c.z + 2), Map));
                        }
                    }
                    if (c.x < x - 1 && !fieldGrid[c.x + 1, c.z])
                    {
                        var door = Find.VisibleMap.thingGrid.ThingsAt(new IntVec3(c.x + 1, c.y, c.z)).ToList().Find(s => s.def.defName == "Door");
                        if (door != null)
                        {
                            adjacentRooms.Add(RoomQuery.RoomAt(new IntVec3(c.x + 2, c.y, c.z), Map));
                        }
                    }
                    if (c.z > 0 && !fieldGrid[c.x, c.z - 1])
                    {
                        var door = Find.VisibleMap.thingGrid.ThingsAt(new IntVec3(c.x, c.y, c.z - 1)).ToList().Find(s => s.def.defName == "Door");
                        if (door != null)
                        {
                            adjacentRooms.Add(RoomQuery.RoomAt(new IntVec3(c.x, c.y, c.z - 2), Map));
                        }
                    }
                    if (c.z > 0 && !fieldGrid[c.x - 1, c.z])
                    {
                        var door = Find.VisibleMap.thingGrid.ThingsAt(new IntVec3(c.x - 1, c.y, c.z)).ToList().Find(s => s.def.defName == "Door");
                        if (door != null)
                        {
                            adjacentRooms.Add(RoomQuery.RoomAt(new IntVec3(c.x - 2, c.y, c.z), Map));
                        }
                    }
                }
            }
        }
示例#29
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (!pawn.RaceProps.Humanlike || (pawn.story != null && pawn.story.WorkTagIsDisabled(WorkTags.Violent)))
            {
                return(null);
            }
            if (pawn.Faction.IsPlayer && pawn.Drafted)
            {
                return(null);
            }

            /*
             * Log.Message(pawn.ToString() +  " priority:" + (GetPriorityWork(pawn)).ToString());
             * Log.Message(pawn.ToString() + " capacityWeight: " + pawn.TryGetComp<CompInventory>().capacityWeight.ToString());
             * Log.Message(pawn.ToString() + " currentWeight: " + pawn.TryGetComp<CompInventory>().currentWeight.ToString());
             * Log.Message(pawn.ToString() + "capacityBulk: " + pawn.TryGetComp<CompInventory>().capacityBulk.ToString());
             * Log.Message(pawn.ToString() + "currentBulk: " + pawn.TryGetComp<CompInventory>().currentBulk.ToString());
             */

            var           brawler         = pawn.story.traits.HasTrait(TraitDefOf.Brawler);
            CompInventory inventory       = pawn.TryGetComp <CompInventory>();
            CompAmmoUser  ammouser        = pawn.TryGetComp <CompAmmoUser>();
            CompAmmoUser  primaryammouser = pawn.equipment.Primary.TryGetComp <CompAmmoUser>();

            if (inventory != null)
            {
                Room room = RoomQuery.RoomAtFast(pawn.Position, pawn.Map);
                // Prefer ranged weapon in inventory
                if (!pawn.Faction.IsPlayer && pawn.equipment != null)
                {
                    if (pawn.equipment.Primary != null && pawn.equipment.Primary.def.IsMeleeWeapon && !brawler &&
                        (pawn.skills.GetSkill(SkillDefOf.Shooting).Level >= pawn.skills.GetSkill(SkillDefOf.Melee).Level || pawn.skills.GetSkill(SkillDefOf.Shooting).Level >= 6))
                    {
                        ThingWithComps InvListGun3 = inventory.rangedWeaponList.Find(thing => thing.TryGetComp <CompAmmoUser>() != null);
                        if (InvListGun3 != null)
                        {
                            Thing ammoInvListGun3 = null;
                            foreach (ThingDef InvListGunDef3 in InvListGun3.TryGetComp <CompAmmoUser>().Props.ammoSet.ammoTypes)
                            {
                                ammoInvListGun3 = inventory.ammoList.Find(thing => thing.def == InvListGunDef3);
                                break;
                            }
                            if (ammoInvListGun3 != null)
                            {
                                inventory.TrySwitchToWeapon(InvListGun3);
                            }
                        }
                    }
                }
                // Drop excess ranged weapon
                if (!pawn.Faction.IsPlayer && pawn.equipment.Primary != null && primaryammouser != null && GetPriorityWork(pawn) == WorkPriority.Unloading && inventory.rangedWeaponList.Count >= 1)
                {
                    Thing ListGun = inventory.rangedWeaponList.Find(thing => pawn.equipment != null && pawn.equipment.Primary != null && thing.TryGetComp <CompAmmoUser>() != null && thing.def != pawn.equipment.Primary.def);
                    if (ListGun != null)
                    {
                        Thing ammoListGun = null;
                        foreach (ThingDef ListGunDef in ListGun.TryGetComp <CompAmmoUser>().Props.ammoSet.ammoTypes)
                        {
                            if (inventory.ammoList.Find(thing => thing.def == ListGunDef) == null)
                            {
                                ammoListGun = ListGun;
                                break;
                            }
                        }
                        if (ammoListGun != null)
                        {
                            Thing droppedWeapon;
                            if (inventory.container.TryDrop(ListGun, pawn.Position, pawn.Map, ThingPlaceMode.Near, ListGun.stackCount, out droppedWeapon))
                            {
                                pawn.jobs.EndCurrentJob(JobCondition.None, true);
                                pawn.jobs.TryTakeOrderedJob(new Job(JobDefOf.DropEquipment, droppedWeapon, 30, true));
                            }
                        }
                    }
                }
                // Find and drop not need ammo from inventory
                if (!pawn.Faction.IsPlayer && inventory.ammoList.Count > 1 && GetPriorityWork(pawn) == WorkPriority.Unloading)
                {
                    Thing WrongammoThing = null;
                    foreach (ThingDef WrongammoDef in primaryammouser.Props.ammoSet.ammoTypes)
                    {
                        WrongammoThing = inventory.ammoList.Find(thing => thing.def != WrongammoDef);
                        break;
                    }
                    if (WrongammoThing != null)
                    {
                        Thing InvListGun = inventory.rangedWeaponList.Find(thing => pawn.equipment != null && pawn.equipment.Primary != null && thing.TryGetComp <CompAmmoUser>() != null && thing.def != pawn.equipment.Primary.def);
                        if (InvListGun != null)
                        {
                            Thing ammoInvListGun = null;
                            foreach (ThingDef InvListGunDef in InvListGun.TryGetComp <CompAmmoUser>().Props.ammoSet.ammoTypes)
                            {
                                ammoInvListGun = inventory.ammoList.Find(thing => thing.def == InvListGunDef);
                                break;
                            }
                            if (ammoInvListGun != null && ammoInvListGun != WrongammoThing)
                            {
                                Thing droppedThingAmmo;
                                if (inventory.container.TryDrop(ammoInvListGun, pawn.Position, pawn.Map, ThingPlaceMode.Near, ammoInvListGun.stackCount, out droppedThingAmmo))
                                {
                                    pawn.jobs.EndCurrentJob(JobCondition.None, true);
                                    pawn.jobs.TryTakeOrderedJob(new Job(JobDefOf.DropEquipment, 30, true));
                                }
                            }
                        }
                        else
                        {
                            Thing droppedThing;
                            if (inventory.container.TryDrop(WrongammoThing, pawn.Position, pawn.Map, ThingPlaceMode.Near, WrongammoThing.stackCount, out droppedThing))
                            {
                                pawn.jobs.EndCurrentJob(JobCondition.None, true);
                                pawn.jobs.TryTakeOrderedJob(new Job(JobDefOf.DropEquipment, 30, true));
                            }
                        }
                    }
                }
                // Find weapon in inventory and try to switch if any ammo in inventory.
                if (GetPriorityWork(pawn) == WorkPriority.Weapon && pawn.equipment.Primary == null)
                {
                    ThingWithComps InvListGun2 = inventory.rangedWeaponList.Find(thing => thing.TryGetComp <CompAmmoUser>() != null);
                    if (InvListGun2 != null)
                    {
                        Thing ammoInvListGun2 = null;
                        foreach (ThingDef InvListGunDef2 in InvListGun2.TryGetComp <CompAmmoUser>().Props.ammoSet.ammoTypes)
                        {
                            ammoInvListGun2 = inventory.ammoList.Find(thing => thing.def == InvListGunDef2);
                            break;
                        }
                        if (ammoInvListGun2 != null)
                        {
                            inventory.TrySwitchToWeapon(InvListGun2);
                        }
                    }
                    // Find weapon with near ammo for ai.
                    if (!pawn.Faction.IsPlayer && pawn.equipment.Primary == null)
                    {
                        Predicate <Thing> validatorWS = (Thing w) => w.def.IsWeapon &&
                                                        w.MarketValue > 500 && pawn.CanReserve(w, 1) &&
                                                        pawn.CanReach(w, PathEndMode.Touch, Danger.Deadly, true) &&
                                                        ((!pawn.Faction.HostileTo(Faction.OfPlayer) && pawn.Map.areaManager.Home[w.Position]) || (pawn.Faction.HostileTo(Faction.OfPlayer))) &&
                                                        (w.Position.DistanceToSquared(pawn.Position) < 15f || room == RoomQuery.RoomAtFast(w.Position, pawn.Map));
                        List <Thing> weapon = (
                            from w in pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.HaulableAlways)
                            where validatorWS(w)
                            where w.def.IsRangedWeapon                             // added this since what we are doing with the weapon list is looking for ammo.
                            orderby w.MarketValue - w.Position.DistanceToSquared(pawn.Position) * 2f descending
                            select w
                            ).ToList();
                        if (weapon != null && weapon.Count > 0)
                        {
                            foreach (Thing thing in weapon)
                            {
                                List <ThingDef> thingDefAmmoList = (from ThingDef g in thing.TryGetComp <CompAmmoUser>().Props.ammoSet.ammoTypes
                                                                    select g).ToList <ThingDef>();
                                Predicate <Thing> validatorA = (Thing t) => t.def.category == ThingCategory.Item &&
                                                               t is AmmoThing && pawn.CanReserve(t, 1) &&
                                                               pawn.CanReach(t, PathEndMode.Touch, Danger.Deadly, true) &&
                                                               (t.Position.DistanceToSquared(pawn.Position) < 20f || room == RoomQuery.RoomAtFast(t.Position, pawn.Map));
                                List <Thing> thingAmmoList = (
                                    from t in pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.HaulableAlways)
                                    where validatorA(t)
                                    select t
                                    ).ToList();
                                if (thingAmmoList.Count > 0 && thingDefAmmoList.Count > 0)
                                {
                                    foreach (Thing th in thingAmmoList)
                                    {
                                        foreach (ThingDef thd in thingDefAmmoList)
                                        {
                                            if (thd == th.def)
                                            {
                                                int ammothingcount = 0;
                                                foreach (ThingDef ammoDef in thing.TryGetComp <CompAmmoUser>().Props.ammoSet.ammoTypes)
                                                {
                                                    ammothingcount += th.stackCount;
                                                }
                                                if (ammothingcount > thing.TryGetComp <CompAmmoUser>().Props.magazineSize * 2)
                                                {
                                                    int numToThing = 0;
                                                    if (inventory.CanFitInInventory(thing, out numToThing))
                                                    {
                                                        if (thing.Position == pawn.Position || thing.Position.AdjacentToCardinal(pawn.Position))
                                                        {
                                                            return(new Job(JobDefOf.Equip, thing)
                                                            {
                                                                checkOverrideOnExpire = true,
                                                                expiryInterval = 100,
                                                                canBash = true,
                                                                locomotionUrgency = LocomotionUrgency.Sprint
                                                            });
                                                        }
                                                        return(GotoForce(pawn, thing, PathEndMode.Touch));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        // else if we didn't find a ranged weapon with available ammo above, lets try a melee weapon.
                        Thing meleeWeapon = (
                            from w in pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.HaulableAlways)
                            where validatorWS(w)
                            where !w.def.IsRangedWeapon                           // Looking for non-ranged weapons.
                            where w.def.IsMeleeWeapon                             // Make sure it's melee capable.
                            orderby w.MarketValue - w.Position.DistanceToSquared(pawn.Position) * 2f descending
                            select w
                            ).FirstOrDefault();
                        if (meleeWeapon != null)
                        {
                            if (meleeWeapon.Position == pawn.Position || meleeWeapon.Position.AdjacentToCardinal(pawn.Position))
                            {
                                return(new Job(JobDefOf.Equip, meleeWeapon)
                                {
                                    checkOverrideOnExpire = true,
                                    expiryInterval = 100,
                                    canBash = true,
                                    locomotionUrgency = LocomotionUrgency.Sprint
                                });
                            }
                            return(GotoForce(pawn, meleeWeapon, PathEndMode.Touch));
                        }
                    }
                }
                // Find ammo
                if ((GetPriorityWork(pawn) == WorkPriority.Ammo || GetPriorityWork(pawn) == WorkPriority.LowAmmo) &&
                    pawn.equipment != null && pawn.equipment.Primary != null && primaryammouser != null)
                {
                    List <ThingDef> curAmmoList = (from ThingDef g in primaryammouser.Props.ammoSet.ammoTypes
                                                   select g).ToList <ThingDef>();
                    if (curAmmoList.Count > 0)
                    {
                        Predicate <Thing> validator = (Thing t) => t is AmmoThing && pawn.CanReserve(t, 1) &&
                                                      pawn.CanReach(t, PathEndMode.Touch, Danger.Deadly, true) &&
                                                      ((pawn.Faction.IsPlayer && !ForbidUtility.IsForbidden(t, pawn)) ||
                                                       (!pawn.Faction.IsPlayer && (!pawn.Faction.HostileTo(Faction.OfPlayer) && pawn.Map.areaManager.Home[t.Position]) || (pawn.Faction.HostileTo(Faction.OfPlayer)))) &&
                                                      (t.Position.DistanceToSquared(pawn.Position) < 20f || room == RoomQuery.RoomAtFast(t.Position, pawn.Map));
                        List <Thing> curThingList = (
                            from t in pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.HaulableAlways)
                            where validator(t)
                            select t
                            ).ToList();
                        foreach (Thing th in curThingList)
                        {
                            foreach (ThingDef thd in curAmmoList)
                            {
                                if (thd == th.def)
                                {
                                    //Defence from low count loot spam
                                    float thw = (th.GetStatValue(CR_StatDefOf.Bulk)) * th.stackCount;
                                    if (thw > 0.5f)
                                    {
                                        if (pawn.Faction.IsPlayer)
                                        {
                                            int SearchRadius = 0;
                                            if (GetPriorityWork(pawn) == WorkPriority.LowAmmo)
                                            {
                                                SearchRadius = 70;
                                            }
                                            else
                                            {
                                                SearchRadius = 30;
                                            }

                                            Thing closestThing = GenClosest.ClosestThingReachable(
                                                pawn.Position,
                                                pawn.Map,
                                                ThingRequest.ForDef(th.def),
                                                PathEndMode.ClosestTouch,
                                                TraverseParms.For(pawn, Danger.None, TraverseMode.ByPawn),
                                                SearchRadius,
                                                x => !x.IsForbidden(pawn) && pawn.CanReserve(x));

                                            if (closestThing != null)
                                            {
                                                int numToCarry = 0;
                                                if (inventory.CanFitInInventory(th, out numToCarry))
                                                {
                                                    return(new Job(JobDefOf.TakeInventory, th)
                                                    {
                                                        count = numToCarry
                                                    });
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (th.Position == pawn.Position || th.Position.AdjacentToCardinal(pawn.Position))
                                            {
                                                int numToCarry = 0;
                                                if (inventory.CanFitInInventory(th, out numToCarry))
                                                {
                                                    return(new Job(JobDefOf.TakeInventory, th)
                                                    {
                                                        count = Mathf.RoundToInt(numToCarry * 0.8f),
                                                        expiryInterval = 150,
                                                        checkOverrideOnExpire = true,
                                                        canBash = true,
                                                        locomotionUrgency = LocomotionUrgency.Sprint
                                                    });
                                                }
                                            }
                                            return(GotoForce(pawn, th, PathEndMode.Touch));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (!pawn.Faction.IsPlayer && pawn.apparel != null && GetPriorityWork(pawn) == WorkPriority.Apparel)
                {
                    if (!pawn.apparel.BodyPartGroupIsCovered(BodyPartGroupDefOf.Torso))
                    {
                        Apparel apparel = this.FindGarmentCoveringPart(pawn, BodyPartGroupDefOf.Torso);
                        if (apparel != null)
                        {
                            int numToapparel = 0;
                            if (inventory.CanFitInInventory(apparel, out numToapparel))
                            {
                                return(new Job(JobDefOf.Wear, apparel)
                                {
                                    ignoreForbidden = true,
                                    locomotionUrgency = LocomotionUrgency.Sprint
                                });
                            }
                        }
                    }
                    if (!pawn.apparel.BodyPartGroupIsCovered(BodyPartGroupDefOf.Legs))
                    {
                        Apparel apparel2 = this.FindGarmentCoveringPart(pawn, BodyPartGroupDefOf.Legs);
                        if (apparel2 != null)
                        {
                            int numToapparel2 = 0;
                            if (inventory.CanFitInInventory(apparel2, out numToapparel2))
                            {
                                return(new Job(JobDefOf.Wear, apparel2)
                                {
                                    ignoreForbidden = true,
                                    locomotionUrgency = LocomotionUrgency.Sprint
                                });
                            }
                        }
                    }

                    /*
                     * if (!pawn.apparel.BodyPartGroupIsCovered(BodyPartGroupDefOf.FullHead))
                     * {
                     *  Apparel apparel3 = this.FindGarmentCoveringPart(pawn, BodyPartGroupDefOf.FullHead);
                     *  if (apparel3 != null)
                     *  {
                     *      int numToapparel3 = 0;
                     *      if (inventory.CanFitInInventory(apparel3, out numToapparel3))
                     *      {
                     *          return new Job(JobDefOf.Wear, apparel3)
                     *          {
                     *              ignoreForbidden = true,
                     *              locomotionUrgency = LocomotionUrgency.Sprint
                     *          };
                     *      }
                     *  }
                     * }
                     */
                }
                return(null);
            }
            return(null);
        }
示例#30
0
        private Apparel FindGarmentCoveringPart(Pawn pawn, BodyPartGroupDef bodyPartGroupDef)
        {
            Room room = pawn.GetRoom();
            Predicate <Thing> validator = (Thing t) => pawn.CanReserve(t, 1) &&
                                          pawn.CanReach(t, PathEndMode.Touch, Danger.Deadly, true) &&
                                          (t.Position.DistanceToSquared(pawn.Position) < 12f || room == RoomQuery.RoomAtFast(t.Position, t.Map));
            List <Thing> aList = (
                from t in pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Apparel)
                orderby t.MarketValue - t.Position.DistanceToSquared(pawn.Position) * 2f descending
                where validator(t)
                select t
                ).ToList();

            foreach (Thing current in aList)
            {
                Apparel ap = current as Apparel;
                if (ap != null && ap.def.apparel.bodyPartGroups.Contains(bodyPartGroupDef) && pawn.CanReserve(ap, 1) && ApparelUtility.HasPartsToWear(pawn, ap.def))
                {
                    return(ap);
                }
            }
            return(null);
        }