Пример #1
0
        public static string ImportPrisonersMails(SoftJailDbContext context, string jsonString)
        {
            var prisonerDtos = JsonConvert.DeserializeObject <IEnumerable <ImportPrisonerDto> >(jsonString);

            var sb = new StringBuilder();

            foreach (var prisonerDto in prisonerDtos)
            {
                if (prisonerDto.Mails.Any(m => !IsValid(m)))
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                if (!IsValid(prisonerDto))
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                DateTime?releaseDate = null;
                if (prisonerDto.ReleaseDate != null)
                {
                    releaseDate = DateTime.ParseExact(prisonerDto.ReleaseDate, "dd/MM/yyyy",
                                                      CultureInfo.InvariantCulture);
                }

                var prisoner = new Prisoner
                {
                    FullName          = prisonerDto.FullName,
                    Nickname          = prisonerDto.Nickname,
                    Age               = prisonerDto.Age,
                    IncarcerationDate = DateTime.ParseExact(prisonerDto.IncarcerationDate, "dd/MM/yyyy", CultureInfo.InvariantCulture),
                    ReleaseDate       = releaseDate,
                    Bail              = prisonerDto.Bail,
                    CellId            = prisonerDto.CellId
                };

                context.Prisoners.Add(prisoner);
                sb.AppendLine($"Imported {prisoner.FullName} {prisoner.Age} years old");

                foreach (var mailDto in prisonerDto.Mails)
                {
                    var mail = new Mail
                    {
                        Description = mailDto.Description,
                        Sender      = mailDto.Sender,
                        Address     = mailDto.Address,
                        Prisoner    = prisoner,
                        PrisonerId  = prisoner.Id
                    };

                    context.Mails.Add(mail);
                }
            }

            context.SaveChanges();

            return(sb.ToString().TrimEnd());
        }
        // GET: PrisonerCells/Details/5
        public ActionResult Details(int id)
        {
            //sending a relation object which includes the cell info and the  Resident prisoners
            var relation = (from item in db.prisonerSatyIns
                            where item.prisonerCellid == id
                            select item).ToList <prisonerSatyIn>();

            cellViewModel cellInfo = new cellViewModel();

            if (relation != null)
            {
                cellInfo.cell      = relation[0].prisonerCell;
                cellInfo.prisoners = new List <Prisoner>();
                for (int i = 0; i < relation.Count; i++)
                {
                    Prisoner prisoner = new Prisoner();
                    prisoner = relation[i].Prisoner;
                    cellInfo.prisoners.Add(prisoner);
                }

                return(View(cellInfo));
            }
            else
            {
                var cell = (from item in db.prisonerCells
                            where item.prisonerCellID == id
                            select item).FirstOrDefault();

                cellInfo.cell = cell;

                return(View(cellInfo));
            }
        }
Пример #3
0
 void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Prisoner"))
     {
         currentlyViewing = other.gameObject.GetComponent <Prisoner>();
     }
 }
Пример #4
0
        public static string ImportPrisonersMails(SoftJailDbContext context, string jsonString)
        {
            var prisonerDto = JsonConvert.DeserializeObject <PrisonerDto[]>(jsonString);

            var validPrisoners = new List <Prisoner>();

            var sb = new StringBuilder();

            foreach (var dto in prisonerDto)
            {
                var isValid = IsValid(dto) &&
                              dto.FullName != null &&
                              dto.Mails.All(IsValid);

                if (isValid)
                {
                    var releaseDate = dto.ReleaseDate == null
                        ? new DateTime?()
                        : DateTime.ParseExact(dto.ReleaseDate,
                                              "dd/MM/yyyy",
                                              CultureInfo.InvariantCulture);

                    var prisoner = new Prisoner
                    {
                        FullName          = dto.FullName,
                        Nickname          = dto.Nickname,
                        Age               = dto.Age,
                        IncarcerationDate = DateTime.ParseExact(dto.IncarcerationDate,
                                                                "dd/MM/yyyy",
                                                                CultureInfo.InvariantCulture),
                        ReleaseDate = releaseDate,
                        Bail        = dto.Bail,
                        CellId      = dto.CellId,
                        Mails       = dto.Mails
                                      .Select(m =>
                                              new Mail
                        {
                            Description = m.Description,
                            Sender      = m.Sender,
                            Address     = m.Address
                        })
                                      .ToArray()
                    };

                    validPrisoners.Add(prisoner);
                    sb.AppendLine($"Imported {prisoner.FullName} {prisoner.Age} years old");
                }
                else
                {
                    sb.AppendLine(InvalidDataMessage);
                }
            }



            context.Prisoners.AddRange(validPrisoners);
            context.SaveChanges();

            return(sb.ToString().TrimEnd());
        }
Пример #5
0
        private void populate()
        {
            //Add prisoners
            Prisoner p = new Prisoner(new Vector2D(10, 10), this);

            p.SB = new SeekBehaviour(p);
            entities.Add(p);

            //Add police
            Police p2 = new Police(new Vector2D(400, 400), this);

            p2.currentGoal = new Goal_SeekToEntity(p2);
            entities.Add(p2);

            //Add houses
            ElectricityHouse e1 = new ElectricityHouse(new Vector2D(800, 400), this);
            ElectricityHouse e2 = new ElectricityHouse(new Vector2D(200, 200), this);
            ElectricityHouse e3 = new ElectricityHouse(new Vector2D(500, 500), this);

            objects.Add(e1);
            objects.Add(e2);
            //objects.Add(e3);

            //Target
            Target        = new Vehicle(new Vector2D(100, 60), this);
            Target.VColor = Color.DarkRed;
            Target.Pos    = new Vector2D(100, 40);
        }
Пример #6
0
        public ActionResult Admit(Prisoner prisoner)
        {
            if (ModelState.IsValid)
            {
                prisoner.Status = PrisonerStatus.Admitted;

                if (prisoner.PrisonerId > 0) // Edit Existing
                {
                    var entry = db.Entry(prisoner);
                    entry.State = EntityState.Modified;
                    entry.Property(o => o.FMD1).IsModified = false;
                }
                else
                {
                    db.Prisoners.Add(prisoner);
                }

                db.SaveChanges();
                PrisonerId = prisoner.PrisonerId;

                return(RedirectToAction("Admit", "FIR"));
                //return RedirectToAction("Admit", "Admission");
            }

            PopulateDropDowns(prisoner);
            return(View(prisoner));
        }
        public void CanNotExecute_1_Prisoners_1_sylabyls()
        {
            Prisoner lastPrisoner = _executionService.Execute(1, 1);

            Assert.IsNotNull(lastPrisoner);
            Assert.AreEqual(lastPrisoner.Number, 1);
        }
        public void CanExecute_10_Prisoners_2_sylabyls()
        {
            Prisoner lastPrisoner = _executionService.Execute(2, 10);

            Assert.IsNotNull(lastPrisoner);
            Assert.AreEqual(lastPrisoner.Number, 5);
        }
Пример #9
0
        public IHttpActionResult PutPrisoner(int id, Prisoner prisoner)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != prisoner.Id)
            {
                return(BadRequest());
            }

            db.Entry(prisoner).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PrisonerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        static void Game(ref Prisoner a, ref Prisoner b, int round)
        {              // ^我後來發現這邊寫法有點多此一舉,物件作為引數被讀入後,本來就是傳址,不是傳值。故不用ref
            switch (a.LastChoice)
            {
            case (Decision.COOPERATE):
                if (b.LastChoice == Decision.COOPERATE)
                {   // win-win
                    a.score += 3;
                    b.score += 3;
                }
                else
                {   // b win
                    b.score += 5;
                }
                break;

            case (Decision.BETRAY):
                if (b.LastChoice == Decision.COOPERATE)
                {   // a win
                    a.score += 5;
                }
                else
                {   // Both Betray
                    a.score += 1;
                    b.score += 1;
                }
                break;
            }
            ScoreBoard(ref a, ref b, round);
            Decision a_choice = a.LastChoice, b_choice = b.LastChoice;

            a.Action(b_choice);
            b.Action(a_choice);
        }// End of void Game
Пример #11
0
 void OnTriggerExit(Collider other)
 {
     if (other.CompareTag("Prisoner"))
     {
         currentlyViewing = null;
     }
 }
Пример #12
0
        public static string ImportPrisonersMails(SoftJailDbContext context, string jsonString)
        {
            PrisonerDto[] prisonersDto = JsonConvert.DeserializeObject <PrisonerDto[]>(jsonString);

            List <Prisoner> validPrisoners = new List <Prisoner>();
            StringBuilder   sb             = new StringBuilder();

            foreach (var prisonerDto in prisonersDto)
            {
                bool isValid = IsValid(prisonerDto) &&
                               prisonerDto.Mails.All(IsValid);

                if (isValid)
                {
                    DateTime?releaseDate = prisonerDto.ReleaseDate == null
                        ? (DateTime?)null
                        : DateTime.ParseExact(
                        prisonerDto.ReleaseDate,
                        "dd/MM/yyyy",
                        CultureInfo.InvariantCulture);

                    Prisoner prisoner = new Prisoner
                    {
                        FullName          = prisonerDto.FullName,
                        Nickname          = prisonerDto.Nickname,
                        Age               = prisonerDto.Age,
                        IncarcerationDate = DateTime.ParseExact(
                            prisonerDto.IncarcerationDate,
                            "dd/MM/yyyy",
                            CultureInfo.InvariantCulture),
                        ReleaseDate = releaseDate,
                        Bail        = prisonerDto.Bail,
                        CellId      = prisonerDto.CellId,
                        Mails       = prisonerDto.Mails
                                      .Select(m => new Mail
                        {
                            Description = m.Description,
                            Sender      = m.Sender,
                            Address     = m.Address
                        })
                                      .ToArray()
                    };

                    validPrisoners.Add(prisoner);
                    sb.AppendLine($"Imported {prisoner.FullName} {prisoner.Age} years old");
                }
                else
                {
                    sb.AppendLine("Invalid Data");
                    continue; // TODO FIX BUG ???
                }
            }

            context.Prisoners.AddRange(validPrisoners);
            context.SaveChanges();

            string result = sb.ToString().TrimEnd();

            return(result);
        }
Пример #13
0
 public void SetupAi()
 {
     prisoner = new Prisoner(NameGenerator.GetName(), (uint)Random.Range(200, 50), 100, 100, Random.Range(0f, 4f), 0);
     this.transform.position = prisoner.GetPrison().transform.position;
     this.GetComponent <Renderer>().material.color = SkinColor.instance.GetSkinColor(prisoner.GetSkinColor());
     agent = this.gameObject.AddComponent <NavMeshAgent>();
 }
        public void Create(Prisoner prisoner)
        {
            int id = int.Parse(_database.Element("prisoners")?.Attribute("lastId").Value ?? string.Empty) + 1;

            prisoner.Id = id;

            string articlesStr = string.Join(",", prisoner.Articles
                                             .Select(a => a.Id.ToString()));

            XElement xPrisoner = new XElement("prisoner",
                                              new XElement("name", prisoner.Name),
                                              new XElement("surname", prisoner.Surname),
                                              new XElement("middleName", prisoner.MiddleName),
                                              new XElement("releaseDate", prisoner.ReleaseDate),
                                              new XElement("arrestDate", prisoner.ArrestDate),
                                              new XElement("notes", prisoner.Notes),
                                              new XElement("cell", prisoner.Cell),
                                              new XElement("casteId", prisoner.CasteId),
                                              new XElement("articles", articlesStr),
                                              new XAttribute("id", id));

            _database.Element("prisoners")?.Add(xPrisoner);
            _database.Element("prisoners").Attribute("lastId").Value = id.ToString();
            _database.Save(_configuration.GetConnectionString("Database"));
        }
Пример #15
0
            // Don't refresh decay timer
            public override void OnEnter(Mobile m)
            {
                if (m.Player && Prisoner != null && Prisoner.CantWalk)
                {
                    string number;

                    switch (Utility.Random(8))
                    {
                    case 0: number = "HELP!"; break;                                                                                       // HELP!

                    case 1: number = "Help me!"; break;                                                                                    // Help me!

                    case 2: number = "Canst thou aid me?!"; break;                                                                         // Canst thou aid me?!

                    case 3: number = "Help a poor prisoner!"; break;                                                                       // Help a poor prisoner!

                    case 4: number = "Help! Please!"; break;                                                                               // Help! Please!

                    case 5: number = "Aaah! Help me!"; break;                                                                              // Aaah! Help me!

                    case 6: number = "Go and get some help!"; break;                                                                       // Go and get some help!

                    default: number = "Quickly, I beg thee! Unlock my chains! If thou dost look at me close thou canst see them.	"; break;     // Quickly, I beg thee! Unlock my chains! If thou dost look at me close thou canst see them.
                    }

                    Prisoner.Yell(true, number);
                }
            }
Пример #16
0
        public ActionResult GetPrisonerDetails(int id)
        {
            Prisoner prisoner = (from item in db.Prisoners
                                 where item.prisonerID == id
                                 select item).FirstOrDefault();


            prisonerSatyIn cell = (from item in db.prisonerSatyIns
                                   where item.prisonerid == id
                                   select item).FirstOrDefault();

            PrisonerWorkA work = (from item in db.PrisonerWorkAs
                                  where item.prisonerid == id
                                  select item).FirstOrDefault();

            prisonerDetails prisonerDetails = new prisonerDetails();

            prisonerDetails.prisoner = prisoner;

            if (cell != null)
            {
                prisonerDetails.cell = cell.prisonerCell;
            }

            if (work != null)
            {
                prisonerDetails.job = work.Job;
            }


            return(View(prisonerDetails));
        }
Пример #17
0
    public void SetupPersonWindow(Prisoner prisoner)
    {
        Oname.text = prisoner.hName;

        this.gameObject.SetActive(true);
        StartCoroutine(GetRequest("https://randomuser.me/api/?inc=picture"));
    }
Пример #18
0
 public void Serialize(IBinarySerializer s)
 {
     Path       = s.SerializeObject <UbiArtPath>(Path, name: nameof(Path));
     IsFree     = s.SerializeBool <uint>(IsFree, name: nameof(IsFree));
     IndexType  = s.Serialize <Index>(IndexType, name: nameof(IndexType));
     VisualType = s.Serialize <Prisoner>(VisualType, name: nameof(VisualType));
 }
Пример #19
0
        //Обробка події натискання на елемент зі списку в'язнів
        protected virtual void listView1_MouseClick(object sender, MouseEventArgs e)
        {
            Prisoner prisoner = (Prisoner)listView1.SelectedItems[0].Tag;

            textBoxName.Text       = prisoner.Name;
            textBoxSurname.Text    = prisoner.Surname;
            textBoxPatronymic.Text = prisoner.Patronymic;
            textBoxAge.Text        = prisoner.Age.ToString();
            textBoxBirth.Text      = prisoner.BirthDate.ToShortDateString();
            textBoxID.Text         = prisoner.ID.ToString();

            var tempRoom = Global.Prison.Rooms.Find(r => r.Number == prisoner.RoomNumber);

            textBoxRoomNumber.Text       = tempRoom.Number.ToString();
            textBoxRoomMax.Text          = tempRoom.Max.ToString();
            textBoxRoomFree.Text         = tempRoom.Free.ToString();
            textBoxStateNumber.Text      = prisoner.State.Number;
            textBoxStateGuardDate.Text   = prisoner.State.GuardDate.ToShortDateString();
            textBoxStateReleaseDate.Text = prisoner.State.ReleaseDate.ToShortDateString();
            textBoxYears.Text            = prisoner.State.Length.Years.ToString();
            textBoxMonths.Text           = prisoner.State.Length.Months.ToString();
            textBoxDays.Text             = prisoner.State.Length.Days.ToString();
            textBoxStateText.Text        = prisoner.State.Text;
            UpdateRelativesList(prisoner);
            UpdateCharacterList(prisoner);
        }
Пример #20
0
        public void doMove(Player player, Prisoner prisoner, int rowOrCol, int row, int col)
        {
            Move lastMove = new Move();

            lastMove.playerId   = player.Id;
            lastMove.prisonerId = prisoner.Id;
            lastMove.rowOrCol   = rowOrCol;
            lastMove.row        = row;
            lastMove.col        = col;

            string lastMoveJson = JsonConvert.SerializeObject(lastMove);

            //string currentAddress;
            foreach (var item in Globals.remoteActorAddresses)
            {
                Globals.ActSys.ActorSelection(item).Tell(lastMoveJson);
            }


            for (int i = 0; i < getNumPlayer() - 1; i++)
            {
                other[i].doMove(other[i].getPlayer(player.Id), other[i].getPrisoner(prisoner.Id), rowOrCol, row, col);
                Console.WriteLine("Player " + other[i].getPlayer(player.Id) + "Prisoner " + prisoner + rowOrCol + row + "col" + col);
            }
        }
Пример #21
0
    //transtions in or out of specified prisoner
    private float transitionP(Prisoner curPrisoner, bool enter)
    {
        float waitTime = 0;

        if (enter)
        {
            //enable third person camera rig and set on target
            prisonerCamera.gameObject.SetActive(true);
            prisonerCamera.gameObject.transform.position = curPrisoner.transform.position;

            //make our camera be set so that it's always looking right behind the player
            prisonerCamera.gameObject.transform.rotation = Quaternion.LookRotation(curPrisoner.gameObject.transform.forward);
            prisonerCamera.LookAngle = prisonerCamera.gameObject.transform.eulerAngles.y;

            //set our current prisoners camera pivot positioning
            Vector3 pivotPosition = prisonerCamera.gameObject.transform.GetChild(0).localPosition;
            pivotPosition.y = curPrisoner.camPivVert;
            pivotPosition.x = curPrisoner.camPivHor;
            //set zoom and pivot
            prisonerCamera.gameObject.transform.GetChild(0).localPosition             = pivotPosition;
            prisonerCamera.gameObject.transform.GetChild(0).GetChild(0).localPosition = new Vector3(0, 0, 0);

            //set our target and enable our animation
            prisonerCamera.SetTarget(curPrisoner.gameObject.transform);
            waitTime            = curPrisoner.bodyTransition(true);
            currentlyPossessing = curPrisoner;
        }
        else
        {
            curPrisoner.stopControlling();
            waitTime            = curPrisoner.bodyTransition(false);
            currentlyPossessing = null;
        }
        return(waitTime);
    }
Пример #22
0
    public GameObject GetSkillShotToPlay()
    {
        if (!GetComponent <Prisoner>())
        {
            print("The actor using this shooting skill script is not character player");
            return(null);
        }
        string charName          = GetComponent <Prisoner>().GetPrisonerName();
        string lastUsedSkillName = Prisoner.GetCharacterLastUsedSkill(charName);

        for (int i = 0; i < skillShotPrefabs.Length; i++)
        {
            if (skillShotPrefabs[i].GetComponent <CharacterSkillShot>())
            {
                if (skillShotPrefabs[i].GetComponent <CharacterSkillShot>().GetShotSkillName() == lastUsedSkillName)
                {
                    return(skillShotPrefabs[i]);
                }
            }
            else if (skillShotPrefabs[i].GetComponent <SupportSkillShot>())
            {
                if (skillShotPrefabs[i].GetComponent <SupportSkillShot>().GetShotSkillName() == lastUsedSkillName)
                {
                    return(skillShotPrefabs[i]);
                }
            }
        }

        return(null);
    }
Пример #23
0
        public override void OnEnter(Mobile m)
        {
            base.OnEnter(m);

            if (m.Player && Prisoner != null && m_Gate != null && m_Gate.Locked)
            {
                int number;

                switch (Utility.Random(10))
                {
                default:
                case 0: number = 502264; break;       // Help a poor prisoner!

                case 1: number = 502266; break;       // Aaah! Help me!

                case 2: number = 1046000; break;      // Help! These savages wish to end my life!

                case 3: number = 1046003; break;      // Quickly! Kill them for me! HELP!!

                case 4: number = 502261;  break;      // HELP!

                case 5: number = 502262; break;       // Help me!

                case 6: number = 502263; break;       // Canst thou aid me?!

                case 7: number = 502265; break;       // Help! Please!

                case 8: number = 502267; break;       // Go and get some help!

                case 9: number = 502268; break;       // Quickly, I beg thee! Unlock my chains! If thou dost look at me close thou canst see them.
                }

                Prisoner.Yell(number);
            }
        }
        public static string ImportPrisonersMails(SoftJailDbContext context, string jsonString)
        {
            var prisonersDto = JsonConvert.DeserializeObject <ImportPrisonerDto[]>(jsonString);

            List <Prisoner> prisoners = new List <Prisoner>();

            StringBuilder sb = new StringBuilder();

            foreach (var prisonerDto in prisonersDto)
            {
                Prisoner prisoner        = Mapper.Map <Prisoner>(prisonerDto);
                bool     isValidPrisoner = IsValid(prisoner);
                bool     hasInvalidMail  = prisoner.Mails.Any(m => IsValid(m) == false);

                if (isValidPrisoner == false || hasInvalidMail == true)
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                prisoners.Add(prisoner);

                sb.AppendLine(string.Format(ImportedPrisonerMessage,
                                            prisoner.FullName,
                                            prisoner.Age));
            }

            context.Prisoners.AddRange(prisoners);
            context.SaveChanges();

            return(sb.ToString().TrimEnd());
        }
        public void Update(Prisoner prisoner)
        {
            int id = prisoner.Id;

            XElement xPrisoner = _database.Element("prisoners")
                                 .Elements("prisoner")
                                 .FirstOrDefault(p => p.Attribute("id")?.Value == id.ToString());

            if (xPrisoner is null)
            {
                return;
            }

            string articlesStr = string.Join(",", prisoner.Articles
                                             .Select(a => a.Id.ToString()));

            xPrisoner.Element("name").Value        = prisoner.Name;
            xPrisoner.Element("surname").Value     = prisoner.Surname;
            xPrisoner.Element("middleName").Value  = prisoner.MiddleName;
            xPrisoner.Element("releaseDate").Value = prisoner.ReleaseDate.ToString();
            xPrisoner.Element("arrestDate").Value  = prisoner.ArrestDate.ToString();
            xPrisoner.Element("notes").Value       = prisoner.Notes ?? String.Empty;
            xPrisoner.Element("cell").Value        = prisoner.Cell;
            xPrisoner.Element("casteId").Value     = prisoner.CasteId.ToString();
            xPrisoner.Element("articles").Value    = articlesStr;

            _database.Save(_configuration.GetConnectionString("Database"));
        }
Пример #26
0
        public static string ImportPrisonersMails(SoftJailDbContext context, string jsonString)
        {
            var deserailizedData = JsonConvert.DeserializeObject <PrisonerImportDto[]>(jsonString);

            var sb = new StringBuilder();

            var prisoners = new List <Prisoner>();

            foreach (var dto in deserailizedData)
            {
                if (!IsValid(dto))
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                var invalidMail = false;
                var mails       = new List <Mail>();
                foreach (var mailDto in dto.Mails)
                {
                    if (!IsValid(mailDto))
                    {
                        invalidMail = true;
                        break;
                    }

                    var mail = new Mail();
                    mail.Description = mailDto.Description;
                    mail.Address     = mailDto.Address;
                    mail.Sender      = mailDto.Sender;
                    mails.Add(mail);
                }

                if (invalidMail)
                {
                    sb.AppendLine(ErrorMessage);
                    continue;
                }

                var prisoner = new Prisoner();
                prisoner.FullName          = dto.FullName;
                prisoner.Nickname          = dto.Nickname;
                prisoner.IncarcerationDate = DateTime.ParseExact(dto.IncarcerationDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                if (dto.ReleaseDate != null)
                {
                    prisoner.ReleaseDate = DateTime.ParseExact(dto.ReleaseDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                }
                prisoner.Mails  = mails;
                prisoner.Age    = dto.Age;
                prisoner.CellId = dto.CellId;
                prisoner.Bail   = dto.Bail;
                sb.AppendLine($"Imported {prisoner.FullName} {prisoner.Age} years old");
                prisoners.Add(prisoner);
            }

            context.Prisoners.AddRange(prisoners);
            context.SaveChanges();

            return(sb.ToString().TrimEnd());
        }
Пример #27
0
        public static string ImportPrisonersMails(SoftJailDbContext context, string jsonString)
        {
            var prisonersDto = JsonConvert.DeserializeObject <List <ImportPrisonersDto> >(jsonString, new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            });

            var           prisoners = new List <Prisoner>();
            StringBuilder sb        = new StringBuilder();

            foreach (var prisoner in prisonersDto)
            {
                var areMailsValid = true;
                if (!IsModelValid(prisoner))
                {
                    sb.AppendLine("Invalid Data");
                    continue;
                }
                var mails = new List <Mail>();
                foreach (var mail in prisoner.Mails)
                {
                    if (!IsModelValid(mail))
                    {
                        sb.AppendLine("Invalid Data");
                        areMailsValid = false;
                        break;
                    }
                    mails.Add(new Mail()
                    {
                        Description = mail.Description,
                        Sender      = mail.Sender,
                        Address     = mail.Address
                    });
                }
                if (!areMailsValid)
                {
                    continue;
                }
                var currentPrisoner = new Prisoner()
                {
                    FullName          = prisoner.FullName,
                    Nickname          = prisoner.Nickname,
                    Age               = prisoner.Age,
                    IncarcerationDate = DateTime.ParseExact(prisoner.IncarcerationDate, "dd/MM/yyyy", CultureInfo.InvariantCulture),
                    ReleaseDate       = DateTime.ParseExact(prisoner.ReleaseDate, "dd/MM/yyyy", CultureInfo.InvariantCulture),
                    Bail              = prisoner.Bail,
                    CellId            = prisoner.CellId,
                    Mails             = mails
                };

                prisoners.Add(currentPrisoner);
                sb.AppendLine($"Imported {currentPrisoner.FullName} {currentPrisoner.Age} years old");
            }

            context.Prisoners.AddRange(prisoners);
            context.SaveChanges();

            return(sb.ToString());
        }
        public static string ImportPrisonersMails(SoftJailDbContext context, string jsonString)
        {
            var sb        = new StringBuilder();
            var prisoners = new List <Prisoner>();

            var prisonerMails = JsonConvert
                                .DeserializeObject <IEnumerable <PrisonerMailInputModel> >(jsonString);

            foreach (var currentPrisoner in prisonerMails)
            {
                if (!IsValid(currentPrisoner) ||
                    !currentPrisoner.Mails.All(IsValid))
                {
                    sb.AppendLine("Invalid Data");
                    continue;
                }

                //dd/MM/yyyy
                var isValidReleaseDate = DateTime.TryParseExact(
                    currentPrisoner.ReleaseDate,
                    "dd/MM/yyyy",
                    CultureInfo.InvariantCulture,
                    DateTimeStyles.None,
                    out DateTime releaseDate);

                var incarcerationDate = DateTime.ParseExact(
                    currentPrisoner.IncarcerationDate,
                    "dd/MM/yyyy",
                    CultureInfo.InvariantCulture);


                var prisoner = new Prisoner
                {
                    FullName          = currentPrisoner.FullName,
                    Nickname          = currentPrisoner.Nickname,
                    Age               = currentPrisoner.Age,
                    Bail              = currentPrisoner.Bail,
                    CellId            = currentPrisoner.CellId,
                    ReleaseDate       = isValidReleaseDate ? (DateTime?)releaseDate : null,
                    IncarcerationDate = incarcerationDate,
                    Mails             = currentPrisoner.Mails.Select(m => new Mail
                    {
                        Sender      = m.Sender,
                        Address     = m.Address,
                        Description = m.Description
                    })
                                        .ToList()
                };

                prisoners.Add(prisoner);

                sb.AppendLine($"Imported {prisoner.FullName} {prisoner.Age} years old");
            }

            context.Prisoners.AddRange(prisoners);
            context.SaveChanges();

            return(sb.ToString().TrimEnd());
        }
Пример #29
0
        public static string ImportPrisonersMails(SoftJailDbContext context, string jsonString)
        {
            var           prisonersModels = JsonConvert.DeserializeObject <PrisonerImportModel[]>(jsonString);
            StringBuilder result          = new StringBuilder();

            foreach (var prisonerModel in prisonersModels)
            {
                var validMailsModels = prisonerModel.Mails.Where(x => IsValid(x)).ToArray();
                if (!IsValid(prisonerModel) ||
                    validMailsModels.Length != prisonerModel.Mails.Length)
                {
                    result.AppendLine(ErrorMessage);
                    continue;
                }

                ParseDateTime(prisonerModel.IncarcerationDate, out DateTime incarcerationDate);
                ParseDateTime(prisonerModel.ReleaseDate, out DateTime releaseDate);

                if (incarcerationDate == null ||
                    (!string.IsNullOrWhiteSpace(prisonerModel.ReleaseDate) &&
                     releaseDate == null))
                {
                    result.AppendLine(ErrorMessage);
                    continue;
                }

                var prisoner = new Prisoner
                {
                    FullName          = prisonerModel.FullName,
                    Nickname          = prisonerModel.Nickname,
                    Age               = prisonerModel.Age,
                    IncarcerationDate = incarcerationDate,
                    ReleaseDate       = releaseDate,
                    Bail              = prisonerModel.Bail,
                    CellId            = prisonerModel.CellId
                };
                context.Prisoners.Add(prisoner);

                foreach (var mailModel in validMailsModels)
                {
                    prisoner.Mails.Add(new Mail
                    {
                        Sender      = mailModel.Sender,
                        Description = mailModel.Description,
                        Address     = mailModel.Address
                    });
                }

                result.AppendLine(
                    GetSuccessfullyImportedPrisonerMessage(
                        prisoner.FullName,
                        prisoner.Age
                        ));
            }

            context.SaveChanges();

            return(result.ToString());
        }
Пример #30
0
    //swaps to the specified prisoner
    public IEnumerator swap(Prisoner curPrisoner)
    {
        //Julia to prisoner
        if (astralForm && (currentlyPossessing == null))
        {
            canSwap = false;
            Vector3 turnDirection = curPrisoner.gameObject.transform.position - Julia.gameObject.transform.position;
            turnDirection.Normalize();
            Julia.stopControlling();
            yield return(StartCoroutine(HOTween.To(Julia.gameObject.transform, turnSpeed, "rotation", Quaternion.LookRotation(turnDirection)).WaitForCompletion()));

            //Fly from current position to prisoner
            Vector3 endFlyPos = new Vector3(curPrisoner.gameObject.transform.position.x, (curPrisoner.gameObject.transform.position.y + 1f), curPrisoner.gameObject.transform.position.z);
            yield return(StartCoroutine(HOTween.To(Julia.gameObject.transform, flyThroughSpeed, "position", endFlyPos).WaitForCompletion()));

            //wait for julia out animation to finish
            yield return(new WaitForSeconds(transitionJ(false)));

            Julia.gameObject.SetActive(false);

            //wait for prisoner in animation to finish
            yield return(new WaitForSeconds(transitionP(curPrisoner, true)));

            //pan the camera out from pivot
            StartCoroutine(panFromHead(curPrisoner));

            //Prisoner to Prisoner
        }
        else if (!astralForm && (currentlyPossessing != null))
        {
            canSwap = false;
            Julia.gameObject.transform.position = currentlyPossessing.transform.position;
            Vector3 turnDirection = curPrisoner.gameObject.transform.position - currentlyPossessing.gameObject.transform.position;
            turnDirection.Normalize();
            Julia.transform.GetComponent <SimpleMouseRotator>().enabled = false;

            //wait for prisoner out animation to finish
            yield return(new WaitForSeconds(transitionP(currentlyPossessing, false)));

            //Fly from prisoner to prisoner,
            prisonerCamera.gameObject.SetActive(false);
            Julia.gameObject.SetActive(true);
            transitionJ(true);
            yield return(StartCoroutine(HOTween.To(Julia.gameObject.transform, turnSpeed, "rotation", Quaternion.LookRotation(turnDirection)).WaitForCompletion()));

            Vector3 endFlyPos = new Vector3(curPrisoner.gameObject.transform.position.x, (curPrisoner.gameObject.transform.position.y + 1f), curPrisoner.gameObject.transform.position.z);
            yield return(StartCoroutine(HOTween.To(Julia.gameObject.transform, flyThroughSpeed, "position", endFlyPos).WaitForCompletion()));

            prisonerCamera.gameObject.SetActive(true);
            transitionJ(false);
            Julia.gameObject.SetActive(false);

            //wait for in animation to finish
            yield return(new WaitForSeconds(transitionP(curPrisoner, true)));

            //pan the camera out from pivot
            StartCoroutine(panFromHead(curPrisoner));
        }
    }
Пример #31
0
 void ReleasePrisoner()
 {
     if (IsTouching((Scene as PlayScene).helipad))
     {
         (Scene as PlayScene).PrisonersInChopper -= 1;
         Prisoner prisoner = new Prisoner { Position = this.Position };
         Scene.AddSprite(prisoner);
         prisoner.BackgroundLayer = (Scene as PlayScene).helipad.BackgroundLayer;
         prisoner.X -= (Scene as PlayScene).helipad.BackgroundLayer.ScrollOffset.X;
         Wait(0.01, prisoner.RunRight);
     }
     IsReleasingPrisoner = false;
 }
Пример #32
0
 public void KilledPrisoner(Prisoner prisoner){
     this.Blood += 100;
     	if(this.Blood > 100){
 	this.Blood = 100;
 	if(this.level == 0)
 		GamePad.SetVibration(playerIndex,0.2f,0);
 	}
 }