Exemplo n.º 1
0
 private void UpdateConstructionCards()
 {
     for (UnitCode i = UnitCode.ROAD; i <= UnitCode.CITY; i++)
     {
         cards[(int)i].UpdateCard(stock[(int)i]);
     }
 }
        public IActionResult AddEdit(String Code, String Desc, String ShortDesc)
        {
            var model = new UnitViewModel(HttpContext);

            model.UnitCodes = dbContext.UnitCodes.ToList();
            try
            {
                var uc = dbContext.UnitCodes.Find(Code);
                if (uc != null)
                {
                    uc.Description      = Desc;
                    uc.ShortDescription = ShortDesc;
                    dbContext.UnitCodes.Update(uc);
                    dbContext.SaveChanges();
                    return(RedirectToAction("Index", model));
                }
                else
                {
                    var uc2 = new UnitCode();
                    uc2.Code             = Code;
                    uc2.Description      = Desc;
                    uc2.ShortDescription = ShortDesc;

                    dbContext.UnitCodes.Add(uc2);
                    dbContext.SaveChanges();
                    return(RedirectToAction("index", model));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(View("index", model));
        }
Exemplo n.º 3
0
        public IActionResult Update([FromBody] UnitCode unitCode)
        {
            try
            {
                UnitCode unitC = dbContext.UnitCodes.Find(unitCode.Code);

                if (unitC != null)
                {
                    unitC.Code             = unitCode.Code;
                    unitC.Description      = unitCode.Description;
                    unitC.ShortDescription = unitCode.ShortDescription;


                    dbContext.UnitCodes.Update(unitC);
                    dbContext.SaveChanges();

                    return(Ok(unitC));
                }
                else
                {
                    throw new Exception($"User Not found with a user ID of '{unitC.Code}'.");
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(GetErrorMessage(ex)));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// </summary>
        /// <param name="_unit"></param>
        /// <param name="default"></param>
        /// <param name="_ownerId"></param>
        /// <returns></returns>
        public int GetScale4Unit(string _unit, int @default, string _ownerId)
        {
            OwnerPersonId = int.Parse(_ownerId);
            if (UnitCode.ToString().Equals(_unit) || _unit == string.Empty && UnitCode == 0)
            {
                return(int.Parse(UnitScale));
            }

            var resourceList = UnitAdvList;

            if (resourceList != null)
            {
                var unitAdv = 0;
                var res     = resourceList.Find(r => r.Unit.Id == _unit);
                if (res != null)
                {
                    unitAdv = res.Точность;
                }
                return(unitAdv == 0 ? @default : unitAdv);

                /*
                 * foreach (UnitAdv unitAdv in resourceList)
                 *  if (unitAdv.Unit.Equals(_unit))
                 *      return unitAdv.Точность == 0 ? @default : unitAdv.Точность;
                 */
            }

            return(@default);
        }
Exemplo n.º 5
0
    public void ReceiveDevelopmentCard(UnitCode receivedCard)
    {
        GiveToPlayer(receivedCard, 1);
        developmentCards.Add(new DevelopmentCardInfo(receivedCard, myPlayer.CurrentTurn));

        if (receivedCard == UnitCode.VICTORY_CARD)
        {
            AddVictoryPoint(UnitCode.VICTORY_CARD);
        }
    }
Exemplo n.º 6
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = base.GetHashCode();
         hashCode = (hashCode * 397) ^ (UnitCode != null ? UnitCode.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (UnitCodeListID != null ? UnitCodeListID.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (UnitCodeListAgencyName != null ? UnitCodeListAgencyName.GetHashCode() : 0);
         return(hashCode);
     }
 }
Exemplo n.º 7
0
    public void GiveToPlayer(UnitCode unit, int amount)
    {
        stock[(int)unit] += amount;

        cards[(int)unit].UpdateCard(stock[(int)unit]);

        if (unit >= UnitCode.BRICK && unit <= UnitCode.WOOL)
        {
            UpdateResourceTotal();
        }

        UpdateConstructionCards();
    }
Exemplo n.º 8
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (cmbPVUnit.SelectedIndex <= 0)
            {
                MessageBox.Show("没有指定显示单位");
                return;
            }
            bool     ret    = false;
            UnitCode pvUnit = (UnitCode)cmbPVUnit.SelectedIndex;

            ret = HartDevice.WritePVUnit(pvUnit);
            MessageBox.Show(ret ? "设置成功" : HartDevice.GetLastError(), "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 设置主变量单位代码
        /// </summary>
        public bool WritePVUnit(long longAddress, UnitCode unitCode)
        {
            RequestPacket request = new RequestPacket()
            {
                LongOrShort = 1,
                Address     = longAddress,
                Command     = 44,
                DataContent = new byte[] { (byte)unitCode },
            };
            ResponsePacket response = Request(request);

            return(response != null);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 写主变量的量程范围
        /// </summary>
        public bool WritePVRange(UnitCode unitCode, float upperRange, float lowerRange)
        {
            if (_ID == null)
            {
                return(false);
            }
            bool ret = _HartComport.WritePVRange(_ID.LongAddress, unitCode, upperRange, lowerRange);

            if (ret)
            {
                _PVOutput = null;
            }
            return(ret);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 将当前的主变量值设置成主变量的下限
        /// </summary>
        public bool SetLowerRangeValue(UnitCode uc, float lv)
        {
            if (_ID == null)
            {
                return(false);
            }
            bool ret = _HartComport.SetLowerRangeValue(_ID.LongAddress, uc, lv);

            if (ret)
            {
                _PVOutput = null;
            }
            return(ret);
        }
Exemplo n.º 12
0
    public bool CanPlayDevelopmentCard(UnitCode card)
    {
        foreach (DevelopmentCardInfo info in developmentCards)
        {
            if (info.turn < myPlayer.CurrentTurn)
            {
                if (info.card == card)
                {
                    return(true);
                }
            }
        }

        return(false);
    }
Exemplo n.º 13
0
        public IActionResult Add([FromBody] UnitCode unit)
        {
            var unitcode = new UnitCode();

            try
            {
                dbContext.UnitCodes.Add(unit);
                dbContext.SaveChanges();
                return(Ok(unitcode));
            }
            catch (Exception ex)
            {
                return(BadRequest(GetErrorMessage(ex)));
            }
        }
Exemplo n.º 14
0
 public void AddUnit(Unit unit)
 {
     if (unit.UnitCode != null && unit.UnitName != null)
     {
         if (unit.UnitName.Trim() != string.Empty && unit.UnitCode.Trim() != string.Empty)
         {
             UnitCodes.Add(unit);
         }
         else
         {
             UnitName = UnitName.Trim();
             UnitCode = UnitCode.Trim();
         }
     }
 }
Exemplo n.º 15
0
    public void ReceiveStolenCard(int senderId, int receivedResourceId)
    {
        // If the resource id is -1, the selected player had no card to give.

        if (receivedResourceId == -1)
        {
            GameObject.Find("EventTextController").GetComponent <EventTextController>().SendEvent(EventTextController.EventCode.NO_RESOURCE_STOLEN, PhotonNetwork.LocalPlayer, senderId);
        }
        else
        {
            UnitCode receivedResource = (UnitCode)receivedResourceId;
            this.GiveToPlayer(receivedResource, 1);
            GameObject.Find("EventTextController").GetComponent <EventTextController>().SendEvent(EventTextController.EventCode.RESOURCE_STOLEN, PhotonNetwork.LocalPlayer, senderId, ColourUtility.GetResourceText(receivedResource));
        }
    }
Exemplo n.º 16
0
        /// <summary>
        /// 设置主变量单位代码
        /// </summary>
        public bool WritePVUnit(UnitCode unitCode)
        {
            if (_ID == null)
            {
                return(false);
            }
            bool ret = _HartComport.WritePVUnit(_ID.LongAddress, unitCode);

            if (ret)
            {
                _PV       = null;
                _PVOutput = null;
                _PVSensor = null;
            }
            return(ret);
        }
Exemplo n.º 17
0
        /// <summary>
        /// 将当前的主变量值设置成主变量的下限
        /// </summary>
        public bool SetLowerRangeValue(long longAddress, UnitCode uc, float lv)
        {
            RequestPacket request = new RequestPacket()
            {
                LongOrShort = 1,
                Address     = longAddress,
                Command     = 0x83,
            };
            List <byte> temp = new List <byte>();

            temp.Add((byte)uc);
            temp.AddRange(BitConverter.GetBytes(lv).Reverse());
            request.DataContent = temp.ToArray();
            ResponsePacket response = Request(request);

            return(response != null);
        }
Exemplo n.º 18
0
    public void GiveAllOfResourceToPlayer(UnitCode resourceCode, int recepientId)
    {
        int amount = stock[(int)resourceCode];

        // Take all cards of this resource type from this player.
        TakeFromPlayer(resourceCode, amount);

        // Send the resources to the player that played the Monopoly card.

        int[] monopolyReplyMessage = new int[3];

        monopolyReplyMessage[0] = (int)GamePlayer.MessageCode.MONOPOLY_REPLY; // Message code.
        monopolyReplyMessage[1] = recepientId;                                // Who should read the message?
        monopolyReplyMessage[2] = amount;                                     // How much of the resource am I sending? (the Monopoly card player knows which resource is being sent)

        GameObject.Find("TurnManager").GetComponent <TurnManager>().SendMove(monopolyReplyMessage, false);
    }
Exemplo n.º 19
0
        /// <summary>
        /// 写主变量的量程范围
        /// </summary>
        public bool WritePVRange(long longAddress, UnitCode unitCode, float upperRange, float lowerRange)
        {
            RequestPacket request = new RequestPacket()
            {
                LongOrShort = 1,
                Address     = longAddress,
                Command     = 35,
            };
            List <byte> d = new List <byte>();

            d.Add((byte)unitCode);
            d.AddRange(BitConverter.GetBytes(upperRange).Reverse());
            d.AddRange(BitConverter.GetBytes(lowerRange).Reverse());
            request.DataContent = d.ToArray();
            ResponsePacket response = Request(request);

            return(response != null);
        }
Exemplo n.º 20
0
        public static async Task SeedAsync(IUnitCodeRepositoryAsync unitCodeRepository)
        {
            // Seed Default UnitCode
            var defaultUnicode = new UnitCode
            {
                Id          = (int)UnitCodes.ROOT_UNITCODE,
                Name        = "Quản trị phần mềm",
                PhoneNumber = "033.248.7344",
                Address     = "Thanh Trì - Hà Nội",
                Describe    = "Quản trị phần mềm"
            };

            var unitCode = await unitCodeRepository.GetUnitCodeByIdAsync(defaultUnicode.Id);

            if (unitCode == null)
            {
                await unitCodeRepository.AddAsync(defaultUnicode);
            }
        }
Exemplo n.º 21
0
    private void TakeVictoryPoint(UnitCode pointSource)
    {
        switch (pointSource)
        {
        case UnitCode.LARGEST_ARMY:
            overviewController.SetVictoryPoint(UnitCode.LARGEST_ARMY, 0);
            playerScore       -= 2;
            hiddenPlayerScore -= 2;
            break;

        case UnitCode.LONGEST_ROAD:
            overviewController.SetVictoryPoint(UnitCode.LONGEST_ROAD, 0);
            playerScore       -= 2;
            hiddenPlayerScore -= 2;
            break;
        }

        GameObject.Find("LeaderboardController").GetComponent <LeaderboardController>().UpdateLeaderboard(PhotonNetwork.LocalPlayer.ActorNumber, playerScore);
    }
Exemplo n.º 22
0
        /// <summary>
        /// </summary>
        /// <param name="_unit"></param>
        /// <param name="default"></param>
        /// <returns></returns>
        public int GetScale4Unit(string _unit, int @default)
        {
            if (UnitCode.ToString().Equals(_unit))
            {
                return(int.Parse(UnitScale));
            }

            var resourceList = UnitAdvList;

            if (resourceList != null)
            {
                foreach (var unitAdv in resourceList)
                {
                    if (unitAdv.Unit.Equals(_unit))
                    {
                        return(unitAdv.Точность == 0 ? @default : unitAdv.Точность);
                    }
                }
            }
            return(@default);
        }
Exemplo n.º 23
0
        public IActionResult Delete(string id)
        {
            try
            {
                UnitCode unitC = dbContext.UnitCodes.Find(id);

                if (unitC != null)
                {
                    dbContext.UnitCodes.Remove(unitC);
                    dbContext.SaveChanges();

                    return(Json(id));
                }
                else
                {
                    throw new Exception($"User Not found with a user ID of '{id}'.");
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(GetErrorMessage(ex)));
            }
        }
Exemplo n.º 24
0
    public void AddVictoryPoint(UnitCode pointSource)
    {
        switch (pointSource)
        {
        case UnitCode.SETTLEMENT:
            playerScore++;
            hiddenPlayerScore++;

            settlementsOnBoard++;
            overviewController.SetVictoryPoint(UnitCode.SETTLEMENT, settlementsOnBoard);
            break;

        case UnitCode.CITY:
            // Also increase the score by only 1 because a settlement was removed (-1 score) and a city was added (+2 score).

            settlementsOnBoard--;
            citiesOnBoard++;

            overviewController.SetVictoryPoint(UnitCode.SETTLEMENT, settlementsOnBoard);
            overviewController.SetVictoryPoint(UnitCode.CITY, citiesOnBoard * 2);

            playerScore++;
            hiddenPlayerScore++;
            break;

        case UnitCode.VICTORY_CARD:

            overviewController.SetVictoryPoint(UnitCode.VICTORY_CARD, stock[(int)UnitCode.VICTORY_CARD]);

            hiddenPlayerScore++;
            break;

        case UnitCode.LARGEST_ARMY:

            overviewController.SetVictoryPoint(UnitCode.LARGEST_ARMY, 2);

            playerScore       += 2;
            hiddenPlayerScore += 2;

            break;

        case UnitCode.LONGEST_ROAD:

            overviewController.SetVictoryPoint(UnitCode.LONGEST_ROAD, 2);

            playerScore       += 2;
            hiddenPlayerScore += 2;

            break;
        }

        if (playerScore == 1)
        {
            // Claim an empty leaderboard slot.
            ClaimLeaderboardSlot();
        }
        else
        {
            // Update the leaderboard.
            GameObject.Find("LeaderboardController").GetComponent <LeaderboardController>().UpdateLeaderboard(PhotonNetwork.LocalPlayer.ActorNumber, playerScore);
        }

        if (CheckWinCondition() == true)
        {
            // Hide end turn button, show Claim Victory button.

            GameObject.Find("BottomPanel").GetComponent <BottomPanel>().EnableClaimVictory();
        }
    }
Exemplo n.º 25
0
        // Pack a ROM.
        public void Pack(string romFolder)
        {
            // File reading content.
            byte[] ReadFile(string path)
            {
                return(System.IO.File.ReadAllBytes(romFolder + "/" + path));
            }

            string[] ReadFileList(string path)
            {
                return(System.IO.File.ReadAllLines(romFolder + "/" + path));
            }

            T ReadJSON <T>(string path)
            {
                return(JsonConvert.DeserializeObject <T>(System.IO.File.ReadAllText(romFolder + "/" + path)));
            }

            List <ushort> validFileIds = new List <ushort>();

            void VerifyFiles(IEnumerable <ushort> fileIds)
            {
                foreach (var u in fileIds)
                {
                    if (validFileIds.Contains(u))
                    {
                        throw new Exception("ERROR: Duplicate overlay file ID in use: 0x" + u.ToString("X"));
                    }
                    else
                    {
                        validFileIds.Add(u);
                    }
                }
            }

            // Get header info and copy it.
            ROM headerInfo = ReadJSON <ROM>("__ROM__/header.json");

            GameTitle            = headerInfo.GameTitle;
            GameCode             = headerInfo.GameCode;
            MakerCode            = headerInfo.MakerCode;
            UnitCode             = headerInfo.UnitCode;
            EncryptionSeedSelect = headerInfo.EncryptionSeedSelect;
            DeviceCapacity       = headerInfo.DeviceCapacity;
            Revision             = headerInfo.Revision;
            Version          = headerInfo.Version;
            Flags            = headerInfo.Flags;
            Arm9EntryAddress = headerInfo.Arm9EntryAddress;
            Arm9LoadAddress  = headerInfo.Arm9LoadAddress;
            Arm7EntryAddress = headerInfo.Arm7EntryAddress;
            Arm7LoadAddress  = headerInfo.Arm7LoadAddress;
            NormalCardControlRegisterSettings = headerInfo.NormalCardControlRegisterSettings;
            SecureCardControlRegisterSettings = headerInfo.SecureCardControlRegisterSettings;
            SecureAreaCRC         = headerInfo.SecureAreaCRC;
            SecureTransferTimeout = headerInfo.SecureTransferTimeout;
            Arm9Autoload          = headerInfo.Arm9Autoload;
            Arm7Autoload          = headerInfo.Arm7Autoload;
            SecureDisable         = headerInfo.SecureDisable;
            HeaderSize            = headerInfo.HeaderSize;

            // Get the Nintendo logo and banner.
            NintendoLogo = ReadFile("__ROM__/nintendoLogo.bin");
            Banner       = ReadFile("__ROM__/banner.bin");

            // Fetch Arm payloads.
            Arm9 = ReadFile("__ROM__/arm9.bin");
            Arm7 = ReadFile("__ROM__/arm7.bin");

            // Get overlays.
            Arm9Overlays = ReadJSON <List <Overlay> >("__ROM__/arm9Overlays.json");
            VerifyFiles(Arm9Overlays.Select(x => x.FileId));
            Arm7Overlays = ReadJSON <List <Overlay> >("__ROM__/arm7Overlays.json");
            VerifyFiles(Arm7Overlays.Select(x => x.FileId));
            foreach (var o in Arm9Overlays)
            {
                o.Data = ReadFile("__ROM__/Arm9/" + o.Id + ".bin");
            }
            foreach (var o in Arm7Overlays)
            {
                o.Data = ReadFile("__ROM__/Arm7/" + o.Id + ".bin");
            }

            // Read files.
            ushort currFolderId = 1;

            string[] fileList = ReadFileList("__ROM__/files.txt");
            Dictionary <string, Folder> folders = new Dictionary <string, Folder>();

            Filesystem = new Filesystem();
            folders.Add("", Filesystem);
            foreach (var s in fileList)
            {
                AddFileToFilesystem(s);
            }

            // Add a file to the filesystem.
            void AddFileToFilesystem(string s)
            {
                // First get its properties.
                string[] fileProperties = s.Split(' ');
                string   filePath       = fileProperties[0];

                if (!filePath.StartsWith("../"))
                {
                    throw new Exception("ERROR: All files must be relative to parent directory \"../\"");
                }
                else
                {
                    filePath = filePath.Substring(3);
                }

                // Get file ID.
                ushort fileId = (ushort)Helper.ReadStringNumber(fileProperties[1]);

                if (validFileIds.Contains(fileId))
                {
                    throw new Exception("ERROR: File ../" + filePath + " uses duplicate file ID 0x" + fileId.ToString("X"));
                }
                else
                {
                    validFileIds.Add(fileId);
                }

                // Proper file name and folder path.
                string fileName   = filePath;
                string folderPath = "";

                while (fileName.Contains('/'))
                {
                    folderPath += "/" + fileName.Substring(0, fileName.IndexOf('/'));
                    fileName    = fileName.Substring(fileName.IndexOf('/') + 1);
                }
                if (folderPath.StartsWith("/"))
                {
                    folderPath = folderPath.Substring(1);
                }

                // New file.
                File f = new File();

                f.Name = fileName;
                f.Id   = fileId;
                f.Data = new GenericFile()
                {
                    Data = ReadFile(filePath)
                };

                // Finally add the file to the folder.
                AddFileToFolder(f, folderPath);
            }

            // Add a file to a folder.
            void AddFileToFolder(File f, string folderPath)
            {
                // First check if the folder exists.
                if (!folders.ContainsKey(folderPath))
                {
                    AppendFolder(folderPath);
                }

                // Add the file to the folder.
                folders[folderPath].Files.Add(f);
            }

            // Append a folder.
            void AppendFolder(string folderPath)
            {
                string folderName     = folderPath;
                string baseFolderPath = "";

                while (folderName.Contains('/'))
                {
                    baseFolderPath += "/" + folderName.Substring(0, folderName.IndexOf('/'));
                    folderName      = folderName.Substring(folderName.IndexOf('/') + 1);
                }
                if (baseFolderPath.StartsWith("/"))
                {
                    baseFolderPath = baseFolderPath.Substring(1);
                }
                if (!folders.ContainsKey(baseFolderPath))
                {
                    AppendFolder(baseFolderPath);
                }
                Folder f = new Folder()
                {
                    Id = currFolderId++, Name = folderName
                };

                folders[baseFolderPath].Folders.Add(f);
                folders.Add(folderPath, f);
            }

            // Fix first file IDs.
            foreach (var f in folders.Values)
            {
                // f.Files = f.Files.OrderBy(x => x.Name).ToList(); = I don't think this should be done.
                if (f.Files.Count > 0)
                {
                    f.FirstFileId = f.Files.OrderBy(x => x.Id).ElementAt(0).Id;
                }
            }

            // Fix folders with no files.
            void FixFolders(Folder f)
            {
                foreach (var folder in f.Folders)
                {
                    FixFolders(folder);
                }
                if (f.Files.Count == 0)
                {
                    f.FirstFileId = f.Folders[0].FirstFileId;
                }
            }

            FixFolders(folders[""]);
        }
Exemplo n.º 26
0
        // Create a new ROM.
        public ROM(string filePath, string conversionPath)
        {
            // Build system.
            if (!conversionPath.Equals(""))
            {
                Directory.CreateDirectory(conversionPath);
                ConversionInfo = new ConversionInfo(conversionPath);
            }

            // Read the file.
            using (Stream s = new FileStream(filePath, FileMode.Open)) {
                // Read general data.
                BinaryReader r = new BinaryReader(s);
                GameTitle            = r.ReadFixedLen(0xC);
                GameCode             = r.ReadFixedLen(0x4);
                MakerCode            = r.ReadFixedLen(0x2);
                UnitCode             = (UnitCode)r.ReadByte();
                EncryptionSeedSelect = r.ReadByte();
                DeviceCapacity       = r.ReadByte();
                r.ReadBytes(7);
                Revision = r.ReadUInt16();
                Version  = r.ReadByte();
                Flags    = r.ReadByte();
                uint arm9Offset = r.ReadUInt32();
                Arm9EntryAddress = r.ReadUInt32();
                Arm9LoadAddress  = r.ReadUInt32();
                uint arm9Size   = r.ReadUInt32();
                uint arm7Offset = r.ReadUInt32();
                Arm7EntryAddress = r.ReadUInt32();
                Arm7LoadAddress  = r.ReadUInt32();
                uint arm7Size          = r.ReadUInt32();
                uint fntOffset         = r.ReadUInt32();
                uint fntSize           = r.ReadUInt32();
                uint fatOffset         = r.ReadUInt32();
                uint fatSize           = r.ReadUInt32();
                uint arm9OverlayOffset = r.ReadUInt32();
                uint arm9OverlayLength = r.ReadUInt32();
                uint arm7OverlayOffset = r.ReadUInt32();
                uint arm7OverlayLength = r.ReadUInt32();
                NormalCardControlRegisterSettings = r.ReadUInt32();
                SecureCardControlRegisterSettings = r.ReadUInt32();
                uint iconBannerOffset = r.ReadUInt32();
                SecureAreaCRC         = r.ReadUInt16();
                SecureTransferTimeout = r.ReadUInt16();
                Arm9Autoload          = r.ReadUInt32();
                Arm7Autoload          = r.ReadUInt32();
                SecureDisable         = r.ReadUInt64();
                uint romSize = r.ReadUInt32() + 0x88;
                HeaderSize = r.ReadUInt32();

                // Read logo.
                r.BaseStream.Position = 0xC0;
                NintendoLogo          = r.ReadBytes(0x9C);
                r.ReadUInt16(); // Nintendo logo CRC. It is literally just the CRC of the logo.
                r.ReadUInt16(); // Header CRC. It is the CRC of everything up to this point (0 to 0x15E).

                // Get banner.
                r.BaseStream.Position = iconBannerOffset;
                ushort bannerVersion = r.ReadUInt16();
                r.BaseStream.Position -= 2;
                Banner = r.ReadBytes((int)BANNER_LENGTHS[bannerVersion]);

                // Code binaries.
                r.BaseStream.Position = arm9Offset;
                Arm9 = r.ReadBytes((int)arm9Size);
                r.BaseStream.Position = arm7Offset;
                Arm7 = r.ReadBytes((int)arm7Size);

                // Get overlays.
                Arm9Overlays = Overlay.LoadOverlays(r, arm9OverlayOffset, arm9OverlayLength);
                Arm7Overlays = Overlay.LoadOverlays(r, arm7OverlayOffset, arm7OverlayLength);
                for (int i = 0; i < Arm9Overlays.Count; i++)
                {
                    r.BaseStream.Position = fatOffset + Arm9Overlays[i].FileId * 8;
                    uint fileStart = r.ReadUInt32();
                    uint fileEnd   = r.ReadUInt32();
                    r.BaseStream.Position = fileStart;
                    Arm9Overlays[i].Data  = r.ReadBytes((int)(fileEnd - fileStart));
                }
                for (int i = 0; i < Arm7Overlays.Count; i++)
                {
                    r.BaseStream.Position = fatOffset + Arm7Overlays[i].FileId * 8;
                    uint fileStart = r.ReadUInt32();
                    uint fileEnd   = r.ReadUInt32();
                    r.BaseStream.Position = fileStart;
                    Arm7Overlays[i].Data  = r.ReadBytes((int)(fileEnd - fileStart));
                }

                // Read filesystem.
                Filesystem = new Filesystem(r, fntOffset, fntSize, fatOffset, fatSize, !conversionPath.Equals(""), ConversionInfo);

                // Dispose.
                r.Dispose();
            }
        }
Exemplo n.º 27
0
 public Prereq Unit(UnitCode code)
 {
     // TODO: Fixme
     return(null);
 }
Exemplo n.º 28
0
 public DevelopmentCardInfo(UnitCode card, int turn)
 {
     this.card = card;
     this.turn = turn;
 }
Exemplo n.º 29
0
    // Found a card that can be played. Remove it from the development cards.
    public void PlayDevelopmentCard(UnitCode card)
    {
        // Remove the first instance of the DevelopmentCardInfo from the list.

        int index = 0;

        foreach (DevelopmentCardInfo info in developmentCards)
        {
            if (info.card == card && info.turn < myPlayer.CurrentTurn)
            {
                break;
            }
            index++;
        }

        developmentCards.RemoveAt(index);
        TakeFromPlayer(card, 1);

        turnDevelopmentCardPlayed = myPlayer.CurrentTurn;

        // Announce the playing to the event text.
        GameObject.Find("EventTextController").GetComponent <EventTextController>().SendEvent(EventTextController.EventCode.DEVELOPMENT_CARD_PLAYED, PhotonNetwork.LocalPlayer, (int)card);

        switch (card)
        {
        case UnitCode.KNIGHT:
            knightCardsPlayed++;
            LargestArmyCheck();

            // Let the local player move the bandit.
            myPlayer.MoveBandit();
            break;

        case UnitCode.EXPANSION:

            // The player may immediately place 2 free roads on the board.

            myPlayer.SetPhase(GamePlayer.Phase.PLAYED_EXPANSION_CARD);
            break;

        case UnitCode.YEAR_OF_PLENTY:

            // The player may immediately take 2 Resource cards from the supply.

            // TODO: Add new phase for HumanPlayer to prevent ending turn while doing this
            GameObject.Find("TradeController").GetComponent <TradeController>().YearOfPlentyInit();

            break;

        case UnitCode.MONOPOLY:

            // The player selects a resource type. Other players give this player ALL of their cards of this resource type.

            // TODO: Add new phase for HumanPlayer to prevent ending turn while doing this
            GameObject.Find("DiscardController").GetComponent <DiscardController>().MonopolyActivated();
            break;

        case UnitCode.VICTORY_CARD:

            // Clicking this card has no effect.
            break;
        }
    }
Exemplo n.º 30
0
    public void TakeFromPlayer(UnitCode unit, int amount)
    {
        if (amount > stock[(int)unit])
        {
            // code in case this happens
            return;
        }

        stock[(int)unit] -= amount;

        cards[(int)unit].UpdateCard(stock[(int)unit]);

        if (unit >= UnitCode.BRICK && unit <= UnitCode.WOOL)
        {
            UpdateResourceTotal();
        }

        UpdateConstructionCards();

        // If the card is a road card, that means that a road was placed on the board by this player.
        // Calculate his longest road, and take the Longest Road card if all the conditions are met.
        if (unit == UnitCode.ROAD)
        {
            // Calculate local player length.
            CalculatePlayerRoadLength();

            // If there is a current owner of this card, recalculate his road length.
            if (longestRoadOwnerId != -1 && longestRoadOwnerId != PhotonNetwork.LocalPlayer.ActorNumber)
            {
                this.longestRoadLength = GameObject.Find("BoardGraph").GetComponent <Graph>().CalculatePlayerRoadLength(longestRoadOwnerId);
            }

            LongestRoadCheck();
        }

        // If the card is a settlement card, check if the settlement dismantles the current longest road.
        if (unit == UnitCode.SETTLEMENT)
        {
            Debug.Log("longest road owner id = " + longestRoadOwnerId);
            //Recalculate longest roads for every player.
            if (longestRoadOwnerId != -1)
            {
                int[] roadLengths = new int[4];

                for (int i = 0; i < 4; i++)
                {
                    if (i >= PhotonNetwork.PlayerList.Length)
                    {
                        continue;
                    }

                    roadLengths[i] = GameObject.Find("BoardGraph").GetComponent <Graph>().CalculatePlayerRoadLength(PhotonNetwork.PlayerList[i].ActorNumber);
                }

                // Find maximum.

                int maxId      = 0;
                int maximumVal = roadLengths[0];
                for (int i = 1; i < roadLengths.Length; i++)
                {
                    if (roadLengths[i] > maximumVal)
                    {
                        maxId      = i;
                        maximumVal = roadLengths[i];
                    }
                }

                for (int i = 0; i < roadLengths.Length; i++)
                {
                    Debug.Log(roadLengths[i]);
                }
                // 2) If the maximumVal is lower than 5, then the Longest Road card goes back into the deck.

                if (maximumVal < 5)
                {
                    //Return the card to the deck.
                    GameObject.Find("EventTextController").GetComponent <EventTextController>().SendEvent(EventTextController.EventCode.LONGEST_ROAD_RETURNED, PhotonNetwork.LocalPlayer);

                    int[] longestRoadReturnedMessage = new int[2];

                    longestRoadReturnedMessage[0] = (int)GamePlayer.MessageCode.LONGEST_ROAD_RETURNED; // Message code.

                    GameObject.Find("TurnManager").GetComponent <TurnManager>().SendMove(longestRoadReturnedMessage, false);
                }
                else
                {
                    int newOwnerId = PhotonNetwork.PlayerList[maxId].ActorNumber;

                    //3) If the newOwnerId is different from the current Largest Road owner id, transfer card to new owner.
                    if (newOwnerId != longestRoadOwnerId)
                    {
                        //The new owner steals the card from the old owner.

                        GameObject.Find("EventTextController").GetComponent <EventTextController>().SendEvent(EventTextController.EventCode.LONGEST_ROAD_STEAL, PhotonNetwork.CurrentRoom.GetPlayer(newOwnerId), longestRoadOwnerId);

                        longestRoadLength  = maximumVal;
                        longestRoadOwnerId = newOwnerId;

                        int[] longestRoadOvertakeMessage = new int[4];

                        longestRoadOvertakeMessage[0] = (int)GamePlayer.MessageCode.LONGEST_ROAD_OVERTAKE; // Message code.
                        longestRoadOvertakeMessage[1] = newOwnerId;                                        // Who sent the message and who has the card.
                        longestRoadOvertakeMessage[2] = maximumVal;                                        // How many cards must the next player to contest for this card pass?
                        longestRoadOvertakeMessage[3] = 0;                                                 // Sending from settlement overtake.

                        GameObject.Find("TurnManager").GetComponent <TurnManager>().SendMove(longestRoadOvertakeMessage, false);
                    }
                }
            }
        }
    }