Inheritance: MonoBehaviour
Exemplo n.º 1
0
Arquivo: Core.cs Projeto: pizyumi/CREA
        public void StartSystem()
        {
            if (isSystemStarted)
                throw new InvalidOperationException("core_started");

            ahdb = new AccountHoldersDatabase(databaseBasepath);
            thdb = new TransactionHistoriesDatabase(databaseBasepath);
            bcadb = new BlockchainAccessDB(databaseBasepath);
            bmdb = new BlockManagerDB(databaseBasepath);
            bdb = new BlockDB(databaseBasepath);
            bfpdb = new BlockFilePointersDB(databaseBasepath);
            ufadb = new UtxoFileAccessDB(databaseBasepath);
            ufpdb = new UtxoFilePointersDB(databaseBasepath);
            ufptempdb = new UtxoFilePointersTempDB(databaseBasepath);
            utxodb = new UtxoDB(databaseBasepath);

            accountHolders = new AccountHolders();
            accountHoldersFactory = new AccountHoldersFactory();

            byte[] ahDataBytes = ahdb.GetData();
            if (ahDataBytes.Length != 0)
                accountHolders.FromBinary(ahDataBytes);
            else
                accountHolders.LoadVersion0();

            transactionHistories = thdb.GetData().Pipe((data) => data.Length == 0 ? new TransactionHistories() : SHAREDDATA.FromBinary<TransactionHistories>(data));
            transactionHistories.UnconfirmedTransactionAdded += (sender, e) =>
            {
                foreach (var accountHolder in accountHolders.AllAccountHolders)
                    foreach (var account in accountHolder.Accounts)
                        foreach (var prevTxOut in e.senders)
                            if (account.Address.Equals(prevTxOut.Address))
                                account.accountStatus.unconfirmedAmount = new CurrencyUnit(account.accountStatus.unconfirmedAmount.rawAmount + prevTxOut.Amount.rawAmount);
            };
            transactionHistories.UnconfirmedTransactionRemoved += (sender, e) =>
            {
                foreach (var accountHolder in accountHolders.AllAccountHolders)
                    foreach (var account in accountHolder.Accounts)
                        foreach (var prevTxOut in e.receivers)
                            if (account.Address.Equals(prevTxOut.Address))
                                account.accountStatus.unconfirmedAmount = new CurrencyUnit(account.accountStatus.unconfirmedAmount.rawAmount - prevTxOut.Amount.rawAmount);
            };

            usableBalanceCache = new CachedData<CurrencyUnit>(() =>
            {
                long rawAmount = 0;
                foreach (var accountHolder in accountHolders.AllAccountHolders)
                    foreach (var account in accountHolder.Accounts)
                        rawAmount += account.accountStatus.usableAmount.rawAmount;
                return new CurrencyUnit(rawAmount);
            });
            unusableBalanceCache = new CachedData<CurrencyUnit>(() =>
            {
                long rawAmount = 0;
                foreach (var accountHolder in accountHolders.AllAccountHolders)
                    foreach (var account in accountHolder.Accounts)
                        rawAmount += account.accountStatus.unusableAmount.rawAmount;
                return new CurrencyUnit(rawAmount);
            });
            unconfirmedBalanceCache = new CachedData<CurrencyUnit>(() =>
            {
                long rawAmount = 0;
                foreach (var accountHolder in accountHolders.AllAccountHolders)
                    foreach (var account in accountHolder.Accounts)
                        rawAmount += account.accountStatus.unconfirmedAmount.rawAmount;
                return new CurrencyUnit(rawAmount);
            });
            usableBalanceWithUnconfirmedCache = new CachedData<CurrencyUnit>(() => new CurrencyUnit(usableBalanceCache.Data.rawAmount - unconfirmedBalanceCache.Data.rawAmount));
            unusableBalanceWithUnconformedCache = new CachedData<CurrencyUnit>(() => new CurrencyUnit(unusableBalanceCache.Data.rawAmount + unconfirmedBalanceCache.Data.rawAmount));

            blockChain = new BlockChain(bcadb, bmdb, bdb, bfpdb, ufadb, ufpdb, ufptempdb, utxodb);
            blockChain.LoadTransactionHistories(transactionHistories);

            //<未改良>暫定?
            if (blockChain.headBlockIndex == -1)
            {
                blockChain.UpdateChain(new GenesisBlock());

                this.RaiseNotification("genesis_block_generated", 5);
            }

            Dictionary<Account, EventHandler<Tuple<CurrencyUnit, CurrencyUnit>>> changeAmountDict = new Dictionary<Account, EventHandler<Tuple<CurrencyUnit, CurrencyUnit>>>();

            Action<bool> _UpdateBalance = (isOnlyUnconfirmed) =>
            {
                if (!isOnlyUnconfirmed)
                {
                    usableBalanceCache.IsModified = true;
                    unusableBalanceCache.IsModified = true;
                }
                unconfirmedBalanceCache.IsModified = true;
                usableBalanceWithUnconfirmedCache.IsModified = true;
                unusableBalanceWithUnconformedCache.IsModified = true;

                BalanceUpdated(this, EventArgs.Empty);
            };

            Action<Account, bool> _AddAddressEvent = (account, isUpdatebalance) =>
            {
                EventHandler<Tuple<CurrencyUnit, CurrencyUnit>> eh = (sender, e) =>
                {
                    account.accountStatus.usableAmount = e.Item1;
                    account.accountStatus.unusableAmount = e.Item2;
                };

                changeAmountDict.Add(account, eh);

                AddressEvent addressEvent = new AddressEvent(account.Address.Hash);
                addressEvent.BalanceUpdated += eh;

                blockChain.AddAddressEvent(addressEvent);

                long rawAmount = 0;
                foreach (var unconfirmedTh in transactionHistories.unconfirmedTransactionHistories.ToArray())
                    foreach (var prevTxOut in unconfirmedTh.senders)
                        if (prevTxOut.Address.Equals(account.Address))
                            rawAmount += prevTxOut.Amount.rawAmount;
                account.accountStatus.unconfirmedAmount = new CurrencyUnit(rawAmount);

                if (isUpdatebalance)
                    _UpdateBalance(false);
            };

            EventHandler<Account> _AccountAdded = (sender, e) =>
            {
                utxodb.Open();

                _AddAddressEvent(e, true);

                utxodb.Close();
            };
            EventHandler<Account> _AccountRemoved = (sender, e) =>
            {
                EventHandler<Tuple<CurrencyUnit, CurrencyUnit>> eh = changeAmountDict[e];

                changeAmountDict.Remove(e);

                AddressEvent addressEvent = blockChain.RemoveAddressEvent(e.Address.Hash);
                addressEvent.BalanceUpdated -= eh;

                _UpdateBalance(false);
            };

            utxodb.Open();

            foreach (var accountHolder in accountHolders.AllAccountHolders)
            {
                foreach (var account in accountHolder.Accounts)
                    _AddAddressEvent(account, false);

                accountHolder.AccountAdded += _AccountAdded;
                accountHolder.AccountRemoved += _AccountRemoved;
            }

            utxodb.Close();

            accountHolders.AccountHolderAdded += (sender, e) =>
            {
                e.AccountAdded += _AccountAdded;
                e.AccountRemoved += _AccountRemoved;
            };
            accountHolders.AccountHolderRemoved += (semder, e) =>
            {
                e.AccountAdded -= _AccountAdded;
                e.AccountRemoved -= _AccountRemoved;
            };

            blockChain.BalanceUpdated += (sender, e) => _UpdateBalance(false);

            _UpdateBalance(false);

            unconfirmedTtxs = new Dictionary<TransferTransaction, TransactionOutput[]>();
            mining = new Mining();
            mining.FoundNonce += (sender, e) => creaNodeTest.DiffuseNewBlock(e);

            blockChain.Updated += (sender, e) =>
            {
                foreach (var block in e)
                    foreach (var tx in block.Transactions)
                        foreach (var txIn in tx.TxInputs)
                        {
                            TransferTransaction contradiction = null;

                            foreach (var unconfirmedTx in unconfirmedTtxs)
                            {
                                foreach (var unconfirmedTxIn in unconfirmedTx.Key.TxInputs)
                                    if (txIn.PrevTxBlockIndex == unconfirmedTxIn.PrevTxBlockIndex && txIn.PrevTxIndex == unconfirmedTxIn.PrevTxIndex && txIn.PrevTxOutputIndex == unconfirmedTxIn.PrevTxOutputIndex)
                                    {
                                        contradiction = unconfirmedTx.Key;

                                        break;
                                    }

                                if (contradiction != null)
                                    break;
                            }

                            if (contradiction != null)
                                unconfirmedTtxs.Remove(contradiction);
                        }

                Mine();
            };

            Mine();

            //creaNodeTest = new CreaNode(ps.NodePort, creaVersion, appnameWithVersion, new FirstNodeInfosDatabase(p2pDirectory));
            creaNodeTest = new CreaNodeTest(blockChain, ps.NodePort, creaVersion, appnameWithVersion);
            creaNodeTest.ConnectionKeeped += (sender, e) => creaNodeTest.SyncronizeBlockchain();
            creaNodeTest.ReceivedNewTransaction += (sender, e) =>
            {
                TransferTransaction ttx = e as TransferTransaction;

                if (ttx == null)
                    return;

                TransactionOutput[] prevTxOuts = new TransactionOutput[ttx.TxInputs.Length];
                for (int i = 0; i < prevTxOuts.Length; i++)
                    prevTxOuts[i] = blockChain.GetMainBlock(ttx.TxInputs[i].PrevTxBlockIndex).Transactions[ttx.TxInputs[i].PrevTxIndex].TxOutputs[ttx.TxInputs[i].PrevTxOutputIndex];

                if (!ttx.Verify(prevTxOuts))
                    return;

                List<TransactionOutput> senders = new List<TransactionOutput>();
                List<TransactionOutput> receivers = new List<TransactionOutput>();

                long sentAmount = 0;
                long receivedAmount = 0;

                for (int i = 0; i < ttx.txInputs.Length; i++)
                    foreach (var accountHolder in accountHolders.AllAccountHolders)
                        foreach (var account in accountHolder.Accounts)
                            if (prevTxOuts[i].Address.Equals(account.Address.Hash))
                            {
                                sentAmount += prevTxOuts[i].Amount.rawAmount;

                                senders.Add(prevTxOuts[i]);
                            }

                for (int i = 0; i < ttx.TxOutputs.Length; i++)
                    foreach (var accountHolder in accountHolders.AllAccountHolders)
                        foreach (var account in accountHolder.Accounts)
                            if (ttx.TxOutputs[i].Address.Equals(account.Address.Hash))
                            {
                                receivedAmount += ttx.TxOutputs[i].Amount.rawAmount;

                                receivers.Add(ttx.TxOutputs[i]);
                            }

                if (senders.Count > 0 || receivers.Count > 0)
                {
                    TransactionHistoryType type = TransactionHistoryType.transfered;
                    if (receivers.Count < ttx.TxOutputs.Length)
                        type = TransactionHistoryType.sent;
                    else if (senders.Count < ttx.TxInputs.Length)
                        type = TransactionHistoryType.received;

                    transactionHistories.AddTransactionHistory(new TransactionHistory(true, false, type, DateTime.MinValue, 0, ttx.Id, senders.ToArray(), receivers.ToArray(), ttx, prevTxOuts, new CurrencyUnit(sentAmount), new CurrencyUnit(receivedAmount - sentAmount)));
                }

                utxodb.Open();

                for (int i = 0; i < ttx.TxInputs.Length; i++)
                    if (blockChain.FindUtxo(prevTxOuts[i].Address, ttx.TxInputs[i].PrevTxBlockIndex, ttx.TxInputs[i].PrevTxIndex, ttx.TxInputs[i].PrevTxOutputIndex) == null)
                        return;

                utxodb.Close();

                foreach (var txIn in ttx.TxInputs)
                    foreach (var unconfirmedTtx in unconfirmedTtxs)
                        foreach (var unconfirmedTxIn in unconfirmedTtx.Key.TxInputs)
                            if (txIn.PrevTxBlockIndex == unconfirmedTxIn.PrevTxBlockIndex && txIn.PrevTxIndex == unconfirmedTxIn.PrevTxIndex && txIn.PrevTxOutputIndex == unconfirmedTxIn.PrevTxOutputIndex)
                                return;

                unconfirmedTtxs.Add(ttx, prevTxOuts);

                Mine();
            };
            creaNodeTest.ReceivedNewBlock += (sender, e) => blockChain.UpdateChain(e).Pipe((ret) => this.RaiseResult("blockchain_update", 5, ret.ToString()));
            //creaNodeTest.Start();

            isSystemStarted = true;
        }
        public override void FillInformation(out string info, out string detailed)
        {
            info = BaseUtils.FieldBuilder.Build("Wealth:;cr;N0".T(EDTx.JournalEntry_Wealth), BankAccount.CurrentWealth, "Notoriety Index:;;N0".T(EDTx.JournalEntry_NotorietyIndex), Crime.Notoriety);

            detailed = "Bank Account".T(EDTx.JournalStatistics_BankAccount) + Environment.NewLine + BankAccount?.Format() + Environment.NewLine +
                       "Combat".T(EDTx.JournalStatistics_Combat) + Environment.NewLine + Combat?.Format() + Environment.NewLine +
                       "Crime".T(EDTx.JournalStatistics_Crime) + Environment.NewLine + Crime?.Format() + Environment.NewLine +
                       "Smuggling".T(EDTx.JournalStatistics_Smuggling) + Environment.NewLine + Smuggling?.Format() + Environment.NewLine +
                       "Trading".T(EDTx.JournalStatistics_Trading) + Environment.NewLine + Trading?.Format() + Environment.NewLine +
                       "Mining".T(EDTx.JournalStatistics_Mining) + Environment.NewLine + Mining?.Format() + Environment.NewLine +
                       "Exploration".T(EDTx.JournalStatistics_Exploration) + Environment.NewLine + Exploration?.Format() + Environment.NewLine +
                       "Passengers".T(EDTx.JournalStatistics_Passengers) + Environment.NewLine + PassengerMissions?.Format() + Environment.NewLine +
                       "Search and Rescue".T(EDTx.JournalStatistics_SearchandRescue) + Environment.NewLine + SearchAndRescue?.Format() + Environment.NewLine +
                       "Engineers".T(EDTx.JournalStatistics_Engineers) + Environment.NewLine + Crafting?.Format() + Environment.NewLine +
                       "Crew".T(EDTx.JournalStatistics_Crew) + Environment.NewLine + Crew?.Format() + Environment.NewLine +
                       "Multicrew".T(EDTx.JournalStatistics_Multicrew) + Environment.NewLine + Multicrew?.Format() + Environment.NewLine +
                       "Materials and Commodity Trading".T(EDTx.JournalStatistics_MaterialsandCommodityTrading) + Environment.NewLine + MaterialTraderStats?.Format() + Environment.NewLine +
                       "CQC".T(EDTx.JournalStatistics_CQC) + Environment.NewLine + CQC?.Format();
        }
Exemplo n.º 3
0
        public static void TerrainBitmapsImportFromFile(string path)
        {
            // Read file in local directory. If it doesn't exist there, read it in root civ2 directory.
            var terrain1 = new Bitmap(640, 480);
            //var terrain1 = new Image<Rgba32>(640, 480);
            string FilePath_local = path + Path.DirectorySeparatorChar + "TERRAIN1.GIF";
            string FilePath_root  = Settings.Civ2Path + "TERRAIN1.GIF";

            if (File.Exists(FilePath_local))
            {
                terrain1 = new Bitmap(FilePath_local);
            }
            else if (File.Exists(FilePath_root))
            {
                terrain1 = new Bitmap(FilePath_root);
            }
            else
            {
                Debug.WriteLine("TERRAIN1.GIF not found!");
            }

            var terrain2 = new Bitmap(640, 480);

            FilePath_local = path + Path.DirectorySeparatorChar + "TERRAIN2.GIF";
            FilePath_root  = Settings.Civ2Path + "TERRAIN2.GIF";
            if (File.Exists(FilePath_local))
            {
                terrain2 = new Bitmap(FilePath_local);
            }
            else if (File.Exists(FilePath_root))
            {
                terrain2 = new Bitmap(FilePath_root);
            }
            else
            {
                Debug.WriteLine("TERRAIN2.GIF not found!");
            }

            // Initialize objects
            Desert     = new Bitmap[4];
            Plains     = new Bitmap[4];
            Grassland  = new Bitmap[4];
            ForestBase = new Bitmap[4];
            HillsBase  = new Bitmap[4];
            MtnsBase   = new Bitmap[4];
            Tundra     = new Bitmap[4];
            Glacier    = new Bitmap[4];
            Swamp      = new Bitmap[4];
            Jungle     = new Bitmap[4];
            Ocean      = new Bitmap[4];
            Coast      = new Bitmap[8, 4];
            River      = new Bitmap[16];
            Forest     = new Bitmap[16];
            Mountains  = new Bitmap[16];
            Hills      = new Bitmap[16];
            RiverMouth = new Bitmap[4];
            Road       = new Bitmap[9];
            Railroad   = new Bitmap[9];

            // Define transparent colors
            Color transparentGray = Color.FromArgb(135, 135, 135);  // Define transparent back color (gray)
            Color transparentPink = Color.FromArgb(255, 0, 255);    // Define transparent back color (pink)
            Color transparentCyan = Color.FromArgb(0, 255, 255);    // Define transparent back color (cyan)

            // Tiles
            for (int i = 0; i < 4; i++)
            {
                Desert[i] = terrain1.Clone(new Rectangle(i + 1 + (i * 64), 1, 64, 32), terrain1.PixelFormat);
                Desert[i].MakeTransparent(transparentGray);
                Desert[i].MakeTransparent(transparentPink);
                Plains[i] = terrain1.Clone(new Rectangle(i + 1 + (i * 64), (2 * 1) + (1 * 32), 64, 32), terrain1.PixelFormat);
                Plains[i].MakeTransparent(transparentGray);
                Plains[i].MakeTransparent(transparentPink);
                Grassland[i] = terrain1.Clone(new Rectangle(i + 1 + (i * 64), (3 * 1) + (2 * 32), 64, 32), terrain1.PixelFormat);
                Grassland[i].MakeTransparent(transparentGray);
                Grassland[i].MakeTransparent(transparentPink);
                ForestBase[i] = terrain1.Clone(new Rectangle(i + 1 + (i * 64), (4 * 1) + (3 * 32), 64, 32), terrain1.PixelFormat);
                ForestBase[i].MakeTransparent(transparentGray);
                ForestBase[i].MakeTransparent(transparentPink);
                HillsBase[i] = terrain1.Clone(new Rectangle(i + 1 + (i * 64), (5 * 1) + (4 * 32), 64, 32), terrain1.PixelFormat);
                HillsBase[i].MakeTransparent(transparentGray);
                HillsBase[i].MakeTransparent(transparentPink);
                MtnsBase[i] = terrain1.Clone(new Rectangle(i + 1 + (i * 64), (6 * 1) + (5 * 32), 64, 32), terrain1.PixelFormat);
                MtnsBase[i].MakeTransparent(transparentGray);
                MtnsBase[i].MakeTransparent(transparentPink);
                Tundra[i] = terrain1.Clone(new Rectangle(i + 1 + (i * 64), (7 * 1) + (6 * 32), 64, 32), terrain1.PixelFormat);
                Tundra[i].MakeTransparent(transparentGray);
                Tundra[i].MakeTransparent(transparentPink);
                Glacier[i] = terrain1.Clone(new Rectangle(i + 1 + (i * 64), (8 * 1) + (7 * 32), 64, 32), terrain1.PixelFormat);
                Glacier[i].MakeTransparent(transparentGray);
                Glacier[i].MakeTransparent(transparentPink);
                Swamp[i] = terrain1.Clone(new Rectangle(i + 1 + (i * 64), (9 * 1) + (8 * 32), 64, 32), terrain1.PixelFormat);
                Swamp[i].MakeTransparent(transparentGray);
                Swamp[i].MakeTransparent(transparentPink);
                Jungle[i] = terrain1.Clone(new Rectangle(i + 1 + (i * 64), (10 * 1) + (9 * 32), 64, 32), terrain1.PixelFormat);
                Jungle[i].MakeTransparent(transparentGray);
                Jungle[i].MakeTransparent(transparentPink);
                Ocean[i] = terrain1.Clone(new Rectangle(i + 1 + (i * 64), (11 * 1) + (10 * 32), 64, 32), terrain1.PixelFormat);
                Ocean[i].MakeTransparent(transparentGray);
                Ocean[i].MakeTransparent(transparentPink);
            }

            // 4 small dither tiles
            DitherBlank = new Bitmap[2, 2];
            DitherDots  = new Bitmap[2, 2];
            for (int tileX = 0; tileX < 2; tileX++)
            {
                for (int tileY = 0; tileY < 2; tileY++)
                {
                    DitherBlank[tileX, tileY] = terrain1.Clone(new Rectangle((tileX * 32) + 1, (tileY * 16) + 447, 32, 16), terrain1.PixelFormat);
                    DitherDots[tileX, tileY]  = DitherBlank[tileX, tileY];
                    DitherDots[tileX, tileY].MakeTransparent(transparentGray);
                    DitherDots[tileX, tileY].MakeTransparent(transparentPink);
                }
            }

            // Blank tile
            Blank = terrain1.Clone(new Rectangle(131, 447, 64, 32), terrain1.PixelFormat);
            Blank.MakeTransparent(transparentGray);

            // Dither base (only useful for grasland?)
            DitherBase = terrain1.Clone(new Rectangle(196, 447, 64, 32), terrain1.PixelFormat);

            // Replace black dither pixels with base pixels
            DitherDesert    = new Bitmap[2, 2]; //4 dither tiles for one 64x32 map tile
            DitherPlains    = new Bitmap[2, 2];
            DitherGrassland = new Bitmap[2, 2];
            DitherForest    = new Bitmap[2, 2];
            DitherHills     = new Bitmap[2, 2];
            DitherMountains = new Bitmap[2, 2];
            DitherTundra    = new Bitmap[2, 2];
            DitherGlacier   = new Bitmap[2, 2];
            DitherSwamp     = new Bitmap[2, 2];
            DitherJungle    = new Bitmap[2, 2];
            Color replacementColor;

            for (int tileX = 0; tileX < 2; tileX++)
            {    // for 4 directions (NE, SE, SW, NW)
                for (int tileY = 0; tileY < 2; tileY++)
                {
                    DitherDesert[tileX, tileY]    = new Bitmap(32, 16);
                    DitherPlains[tileX, tileY]    = new Bitmap(32, 16);
                    DitherGrassland[tileX, tileY] = new Bitmap(32, 16);
                    DitherForest[tileX, tileY]    = new Bitmap(32, 16);
                    DitherHills[tileX, tileY]     = new Bitmap(32, 16);
                    DitherMountains[tileX, tileY] = new Bitmap(32, 16);
                    DitherTundra[tileX, tileY]    = new Bitmap(32, 16);
                    DitherGlacier[tileX, tileY]   = new Bitmap(32, 16);
                    DitherSwamp[tileX, tileY]     = new Bitmap(32, 16);
                    DitherJungle[tileX, tileY]    = new Bitmap(32, 16);
                    for (int col = 0; col < 32; col++)
                    {
                        for (int row = 0; row < 16; row++)
                        {
                            // replacementColor = DitherBlank.GetPixel(tileX * 32 + col, tileY * 16 + row);
                            replacementColor = DitherBlank[tileX, tileY].GetPixel(col, row);
                            if (replacementColor == Color.FromArgb(0, 0, 0))
                            {
                                DitherDesert[tileX, tileY].SetPixel(col, row, Desert[0].GetPixel((tileX * 32) + col, (tileY * 16) + row));
                                DitherPlains[tileX, tileY].SetPixel(col, row, Plains[0].GetPixel((tileX * 32) + col, (tileY * 16) + row));
                                DitherGrassland[tileX, tileY].SetPixel(col, row, Grassland[0].GetPixel((tileX * 32) + col, (tileY * 16) + row));
                                DitherForest[tileX, tileY].SetPixel(col, row, ForestBase[0].GetPixel((tileX * 32) + col, (tileY * 16) + row));
                                DitherHills[tileX, tileY].SetPixel(col, row, HillsBase[0].GetPixel((tileX * 32) + col, (tileY * 16) + row));
                                DitherMountains[tileX, tileY].SetPixel(col, row, MtnsBase[0].GetPixel((tileX * 32) + col, (tileY * 16) + row));
                                DitherTundra[tileX, tileY].SetPixel(col, row, Tundra[0].GetPixel((tileX * 32) + col, (tileY * 16) + row));
                                DitherGlacier[tileX, tileY].SetPixel(col, row, Glacier[0].GetPixel((tileX * 32) + col, (tileY * 16) + row));
                                DitherSwamp[tileX, tileY].SetPixel(col, row, Swamp[0].GetPixel((tileX * 32) + col, (tileY * 16) + row));
                                DitherJungle[tileX, tileY].SetPixel(col, row, Jungle[0].GetPixel((tileX * 32) + col, (tileY * 16) + row));
                            }
                            else
                            {
                                DitherDesert[tileX, tileY].SetPixel(col, row, Color.Transparent);
                                DitherPlains[tileX, tileY].SetPixel(col, row, Color.Transparent);
                                DitherGrassland[tileX, tileY].SetPixel(col, row, Color.Transparent);
                                DitherForest[tileX, tileY].SetPixel(col, row, Color.Transparent);
                                DitherHills[tileX, tileY].SetPixel(col, row, Color.Transparent);
                                DitherMountains[tileX, tileY].SetPixel(col, row, Color.Transparent);
                                DitherTundra[tileX, tileY].SetPixel(col, row, Color.Transparent);
                                DitherGlacier[tileX, tileY].SetPixel(col, row, Color.Transparent);
                                DitherSwamp[tileX, tileY].SetPixel(col, row, Color.Transparent);
                                DitherJungle[tileX, tileY].SetPixel(col, row, Color.Transparent);
                            }
                        }
                    }
                }
            }

            // Rivers, Forest, Mountains, Hills
            for (int i = 0; i < 16; i++)
            {
                River[i] = terrain2.Clone(new Rectangle((i % 8) + 1 + ((i % 8) * 64), 3 + (i / 8) + ((2 + (i / 8)) * 32), 64, 32), terrain2.PixelFormat);
                River[i].MakeTransparent(transparentGray);
                River[i].MakeTransparent(transparentPink);
                Forest[i] = terrain2.Clone(new Rectangle((i % 8) + 1 + ((i % 8) * 64), 5 + (i / 8) + ((4 + (i / 8)) * 32), 64, 32), terrain2.PixelFormat);
                Forest[i].MakeTransparent(transparentGray);
                Forest[i].MakeTransparent(transparentPink);
                Mountains[i] = terrain2.Clone(new Rectangle((i % 8) + 1 + ((i % 8) * 64), 7 + (i / 8) + ((6 + (i / 8)) * 32), 64, 32), terrain2.PixelFormat);
                Mountains[i].MakeTransparent(transparentGray);
                Mountains[i].MakeTransparent(transparentPink);
                Hills[i] = terrain2.Clone(new Rectangle((i % 8) + 1 + ((i % 8) * 64), 9 + (i / 8) + ((8 + (i / 8)) * 32), 64, 32), terrain2.PixelFormat);
                Hills[i].MakeTransparent(transparentGray);
                Hills[i].MakeTransparent(transparentPink);
            }

            // River mouths
            for (int i = 0; i < 4; i++)
            {
                RiverMouth[i] = terrain2.Clone(new Rectangle(i + 1 + (i * 64), (11 * 1) + (10 * 32), 64, 32), terrain2.PixelFormat);
                RiverMouth[i].MakeTransparent(transparentGray);
                RiverMouth[i].MakeTransparent(transparentPink);
                RiverMouth[i].MakeTransparent(transparentCyan);
            }

            // Coast
            for (int i = 0; i < 8; i++)
            {
                Coast[i, 0] = terrain2.Clone(new Rectangle((2 * i) + 1 + (2 * i * 32), 429, 32, 16), terrain2.PixelFormat);                                // N
                Coast[i, 0].MakeTransparent(transparentGray);
                Coast[i, 1] = terrain2.Clone(new Rectangle((2 * i) + 1 + (2 * i * 32), 429 + (1 * 1) + (1 * 16), 32, 16), terrain2.PixelFormat);           // S
                Coast[i, 1].MakeTransparent(transparentGray);
                Coast[i, 2] = terrain2.Clone(new Rectangle((2 * i) + 1 + (2 * i * 32), 429 + (2 * 1) + (2 * 16), 32, 16), terrain2.PixelFormat);           // W
                Coast[i, 2].MakeTransparent(transparentGray);
                Coast[i, 3] = terrain2.Clone(new Rectangle((2 * (i + 1)) + (((2 * i) + 1) * 32), 429 + (2 * 1) + (2 * 16), 32, 16), terrain2.PixelFormat); // E
                Coast[i, 3].MakeTransparent(transparentGray);
            }

            // Road & railorad
            for (int i = 0; i < 9; i++)
            {
                Road[i] = terrain1.Clone(new Rectangle(i + 1 + (i * 64), 364, 64, 32), terrain1.PixelFormat);
                Road[i].MakeTransparent(transparentGray);
                Road[i].MakeTransparent(transparentPink);
                Railroad[i] = terrain1.Clone(new Rectangle(i + 1 + (i * 64), 397, 64, 32), terrain1.PixelFormat);
                Railroad[i].MakeTransparent(transparentGray);
                Railroad[i].MakeTransparent(transparentPink);
            }

            Irrigation = terrain1.Clone(new Rectangle(456, 100, 64, 32), terrain1.PixelFormat);
            Irrigation.MakeTransparent(transparentGray);
            Irrigation.MakeTransparent(transparentPink);

            Farmland = terrain1.Clone(new Rectangle(456, 133, 64, 32), terrain1.PixelFormat);
            Farmland.MakeTransparent(transparentGray);
            Farmland.MakeTransparent(transparentPink);

            Mining = terrain1.Clone(new Rectangle(456, 166, 64, 32), terrain1.PixelFormat);
            Mining.MakeTransparent(transparentGray);
            Mining.MakeTransparent(transparentPink);

            Pollution = terrain1.Clone(new Rectangle(456, 199, 64, 32), terrain1.PixelFormat);
            Pollution.MakeTransparent(transparentGray);
            Pollution.MakeTransparent(transparentPink);

            Shield = terrain1.Clone(new Rectangle(456, 232, 64, 32), terrain1.PixelFormat);
            Shield.MakeTransparent(transparentGray);
            Shield.MakeTransparent(transparentPink);

            terrain1.Dispose();
            terrain2.Dispose();
        }
Exemplo n.º 4
0
        private void handleFirstClickObject(Player player, Packet packet)
        {
            int    objectX  = packet.readLEShort();
            ushort objectId = (ushort)packet.readShortA();
            int    objectY  = packet.readUShort();

            if (objectX < 1000 || objectY < 1000 || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null)
            {
                return;
            }
            SkillHandler.resetAllSkills(player);
            player.getPackets().closeInterfaces();
            Console.WriteLine("First object click = " + objectId + " " + objectX + " " + objectY);
            if (RuneCraft.wantToRunecraft(player, objectId, objectX, objectY))
            {
                return;
            }
            else if (RuneCraft.enterRift(player, objectId, objectX, objectY))
            {
                return;
            }
            else if (RuneCraft.enterViaTiara(player, objectId, objectX, objectY))
            {
                player.setFaceLocation(new Location(objectX, objectY, player.getLocation().getZ()));
                return;
            }
            else if (RuneCraft.leaveAltar(player, objectId, objectX, objectY))
            {
                return;
            }
            else if (Barrows.leaveCrypt(player, objectId, objectX, objectY))
            {
                return;
            }
            else if (Barrows.tryOpenCoffin(player, objectId))
            {
                return;
            }
            else if (Barrows.openTunnelDoor(player, objectId, objectX, objectY))
            {
                return;
            }
            else if (Thieving.wantToThieveChest(player, objectId, objectX, objectY))
            {
                return;
            }
            else if (Agility.doAgility(player, objectId, objectX, objectY))
            {
                return;
            }
            else if (Farming.interactWithPatch(player, objectId, objectX, objectY, -1))
            {
                return;
            }
            else if (Server.getGlobalObjects().getDoors().useDoor(player, objectId, objectX, objectY, player.getLocation().getZ()))
            {
                return;
            }
            else if (LaddersAndStairs.useObject(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 1))
            {
                return;
            }
            else if (WildernessObelisks.useWildernessObelisk(player, objectId, new Location(objectX, objectY, player.getLocation().getZ())))
            {
                return;
            }
            if (player.getTemporaryAttribute("unmovable") != null)
            {
                return;
            }
            player.setFaceLocation(new Location(objectX, objectY, player.getLocation().getZ()));
            switch (objectId)
            {
            case 2492:                 // essence mine portals
                RuneCraft.leaveEssMine(player, new Location(objectX, objectY, player.getLocation().getZ()));
                break;

            case 5959:
            case 5960:
                Wilderness.handleLever(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()));
                break;

            case 733:                 // Wilderness web
                Wilderness.slashWeb(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()));
                break;

            case 28089:                 // GE desk
                Server.getGrandExchange().clickDesk(player, objectX, objectY, 1);
                break;

            case 9359:                 // Tzhaar main exit
                TzHaar.exitTzhaar(player);
                break;

            case 31284:                 // Tzhaar entrance
                TzHaar.enterTzhaar(player);
                break;

            case 9357:                 // Fight cave exit
                FightCave.exitCave(player, objectX, objectY);
                break;

            case 9356:                 // Fight cave entrance
                FightCave.enterCave(player);
                break;

            case 9391:                 // Tzhaar fight pits viewing orb
                Server.getMinigames().getFightPits().useOrb(player, -1);
                break;

            case 9369:                 // Tzhaar pits main entrance
            case 9368:                 // Tzhaar pits game door
                Server.getMinigames().getFightPits().useDoor(player, objectId);
                break;

            case 3617:                 // Agility arena ladder
                AgilityArena.enterArena(player, objectX, objectY);
                break;

            case 3618:
                if (Location.atAgilityArena(player.getLocation()))
                {
                    AgilityArena.exitArena(player, objectX, objectY);
                }
                break;

            case 6:     // Dwarf multicannon
                DwarfCannon cannon = player.getCannon();
                Location    l      = new Location(objectX, objectY, player.getLocation().getZ());
                if (cannon == null || (cannon != null & !l.withinDistance(cannon.getLocation(), 2)))
                {
                    player.getPackets().sendMessage("This isn't your cannon!");
                    break;
                }
                cannon.fireCannon();
                break;

            case 7:     //Cannon base only
            case 8:     //Cannon stand
            case 9:     //Cannon barrels
                DwarfCannon cannonPickup   = player.getCannon();
                Location    cannonLocation = new Location(objectX, objectY, player.getLocation().getZ());
                if (cannonPickup == null || (cannonPickup != null & !cannonLocation.withinDistance(cannonPickup.getLocation(), 2)))
                {
                    player.getPackets().sendMessage("This isn't your cannon!");
                    break;
                }
                cannonPickup.pickupCannon();
                break;

            case 11601:                 // Clay oven
                player.getPackets().modifyText("Please use the item on the oven.", 210, 1);
                player.getPackets().sendChatboxInterface(210);
                break;

            case 10284:                 // Barrows chest
                Barrows.openChest(player);
                break;

            case 4483:                 // Castle wars bank chest.
            case 21301:                // Neitiznot bank chest
                player.getBank().openBank(false, objectX, objectY);
                break;

            case 1276:                 // Normal tree
            case 1278:                 // Normal tree
            case 2409:                 // Normal tree
            case 1277:                 // Normal tree with but different coloured stump
            case 3034:                 // Normal tree with dark stump
            case 3033:                 // Normal tree with dark stump
            case 10041:                // Normal tree
            case 1282:                 // Dead tree
            case 1283:                 // Dead tree
            case 1284:                 // Dead tree
            case 1285:                 // Dead tree
            case 1286:                 // Dead tree
            case 1289:                 // Dead tree
            case 1290:                 // Dead tree
            case 1365:                 // Dead tree
            case 1383:                 // Dead tree
            case 1384:                 // Dead tree
            case 1291:                 // Dead tree
            case 3035:                 // Dead tree
            case 3036:                 // Dead tree
            case 1315:                 // Evergreen
            case 1316:                 // Evergreen
            case 1318:                 // Snowy Evergreen
            case 1319:                 // Snowy Evergreen
            case 1330:                 // Snow covered tree
            case 1331:                 // Snow covered tree
            case 1332:                 // Snow covered tree
            case 3879:                 // Evergreen from elf land
            case 3881:                 // Evergreen from elf land (slightly bigger than one above)
            case 3882:                 // Evergreen from elf land (slightly bigger than one above)
            case 3883:                 // Small Evergreen from elf land
            case 1280:                 // Normal tree orange stump
            case 14309:                // PC game island tree
                Woodcutting.tryCutTree(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 0, true);
                break;

            case 1281:                 // Normal Oak tree
            case 3037:                 // Oak tree dark stump
                Woodcutting.tryCutTree(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 1, true);
                break;

            case 1308:                 // Normal Willow tree
            case 5551:                 // Normal Willow tree
            case 5552:                 // Normal Willow tree
            case 5553:                 // Normal Willow tree
                Woodcutting.tryCutTree(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 2, true);
                break;

            case 2023:                 // Achey tree
                Woodcutting.tryCutTree(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 3, true);
                break;

            case 9036:                 // Normal Teak tree
            case 15062:                // Normal Teak tree (same as above?)
                Woodcutting.tryCutTree(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 4, true);
                break;

            case 1307:                // Normal Maple tree
            case 4674:                // Exactly same as above
                Woodcutting.tryCutTree(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 5, true);
                break;

            case 2289:                 // Normal Hollow tree
            case 4060:                 // Normal Hollow tree (bigger than above)
                Woodcutting.tryCutTree(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 6, true);
                break;

            case 9034:                 // Normal Mahogany tree
                Woodcutting.tryCutTree(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 7, true);
                break;

            case 21273:                 // Normal Arctic pine
                Woodcutting.tryCutTree(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 8, true);
                break;

            case 28951:                 // Normal Eucalyptus tree
            case 28952:                 // Normal Eucalyptus tree (smaller)
            case 28953:                 // Normal Eucalyptus tree (smallest)
                Woodcutting.tryCutTree(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 9, true);
                break;

            case 1309:                 // Yew tree
                Woodcutting.tryCutTree(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 10, true);
                break;

            case 1306:                 // Normal Magic tree
                Woodcutting.tryCutTree(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 11, true);
                break;

            case 3203:                 // Duel arena trapdoors.
                if (player.getDuel() != null)
                {
                    player.getDuel().forfeitDuel(objectX, objectY);
                    break;
                }
                break;

            case 7152:                 // Abyss tendrils.
            case 7144:
                AbyssObstacles.chopTendrils(player, objectX, objectY);
                break;

            case 7147:                 // Abyss tunnel.
                AbyssObstacles.useAgilityTunnel(player, objectX, objectY);
                break;

            case 7146:                 // Abyss eyes.
            case 7150:
                AbyssObstacles.passEyes(player, objectX, objectY);
                break;

            case 7151:                 // Abyss boil.
            case 7145:
                AbyssObstacles.burnBoil(player, objectX, objectY);
                break;

            case 7153:                 // Abyss mining rock.
            case 7143:
                AbyssObstacles.mineRock(player, objectX, objectY);
                break;

            case 2213:                 // Catherby bank booth.
            case 11402:                // Varrock bank booth.
            case 11758:                // Falador bank booth.
            case 36786:                // Lumbridge bank booth.
            case 35647:                // Al-Kharid bank booth.
            case 25808:                // Seers bank booth.
            case 34752:                // Ardougne bank booth.
            case 26972:                // Edgeville bank booth.
            case 29085:                // Ooglog bank booth.
                player.getBank().openBank(true, objectX, objectY);
                break;

            case 2491:                 // Essence rock
                Mining.tryMineRock(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 0, true);
                break;

            case 11954:                 // Iron rocks
            case 11955:
            case 11956:
            case 14856:
            case 14857:
            case 14858:
            case 31071:
            case 31072:
            case 31073:
            case 32441:
            case 32442:
            case 32443:
                Mining.tryMineRock(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 6, true);
                break;

            case 11948:                 // Silver rocks
            case 11949:
            case 11950:
            case 11165:
            case 11186:
            case 11187:
            case 11188:
            case 31074:
            case 31075:
            case 31076:
            case 32444:
            case 32445:
            case 32446:
            case 15579:
            case 15580:
            case 15581:
                Mining.tryMineRock(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 8, true);
                break;

            case 15504:                 // Clay rocks
            case 15503:
            case 15505:
            case 11189:
            case 11190:
            case 11191:
            case 31062:
            case 31063:
            case 31064:
            case 32429:
            case 32430:
            case 32431:
                Mining.tryMineRock(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 1, true);
                break;

            case 11960:                 // Copper rocks
            case 11961:
            case 11962:
            case 11936:
            case 11937:
            case 11938:
            case 31080:
            case 31081:
            case 31082:
                Mining.tryMineRock(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 2, true);
                break;

            case 11959:                 // Tin rocks
            case 11958:
            case 11957:
            case 11933:
            case 11934:
            case 11935:
            case 31077:
            case 31078:
            case 31079:
                Mining.tryMineRock(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 3, true);
                break;

            case 11930:                 // Coal rocks
            case 11931:
            case 11932:
            case 14850:
            case 14851:
            case 14852:
            case 31068:
            case 31069:
            case 31070:
            case 32426:
            case 32427:
            case 32428:
                Mining.tryMineRock(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 9, true);
                break;

            case 11951:                 // Gold rocks
            case 11952:
            case 11953:
            case 11183:
            case 11184:
            case 11185:
            case 31065:
            case 31066:
            case 31067:
            case 32432:
            case 32433:
            case 32434:
            case 15576:
            case 15577:
            case 15578:
                Mining.tryMineRock(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 10, true);
                break;

            case 11945:                 // Mithril rocks
            case 11946:
            case 11947:
            case 11942:
            case 11943:
            case 11944:
            case 14853:
            case 14854:
            case 14855:
            case 31086:
            case 31087:
            case 31088:
            case 32438:
            case 32439:
            case 32440:
                Mining.tryMineRock(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 11, true);
                break;

            case 11963:                 // Adamant rocks
            case 11964:
            case 11965:
            case 11939:
            case 11940:
            case 11941:
            case 14862:
            case 14863:
            case 14864:
            case 31083:
            case 31084:
            case 31085:
            case 32435:
            case 32436:
            case 32437:
                Mining.tryMineRock(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 12, true);
                break;

            case 14859:                 // Rune rocks
            case 14860:
            case 14861:
                Mining.tryMineRock(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 13, true);
                break;

            case 11552:                 // Empty rocks
            case 11553:
            case 11554:
            case 11555:
            case 11556:
            case 31059:
            case 31060:
            case 31061:
            case 14832:
            case 14833:
            case 14834:
            case 33400:
            case 33401:
            case 33402:
            case 15582:
            case 15583:
            case 15584:
                Mining.displayEmptyRockMessage(player, new Location(objectX, objectY, player.getLocation().getZ()));
                break;

            case 23271:                 // Wilderness ditch
                Wilderness.crossDitch(player, objectX, objectY);
                break;
            }
        }
Exemplo n.º 5
0
        private void handleSecondClickObject(Player player, Packet packet)
        {
            int    objectY  = packet.readLEShortA();
            int    objectX  = packet.readLEShort();
            ushort objectId = packet.readUShort();

            Console.WriteLine("Second object click = " + objectId + " " + objectX + " " + objectY);
            if (player.getTemporaryAttribute("unmovable") != null)
            {
                return;
            }
            if (objectX < 1000 || objectY < 1000 || player.isDead() || player.getTemporaryAttribute("cantDoAnything") != null)
            {
                return;
            }
            SkillHandler.resetAllSkills(player);
            player.getPackets().closeInterfaces();
            player.setFaceLocation(new Location(objectX, objectY, player.getLocation().getZ()));
            if (Thieving.wantToThieveStall(player, objectId, objectX, objectY))
            {
                return;
            }
            else if (Farming.interactWithPatch(player, objectId, objectX, objectY, -1))
            {
                return;
            }
            else if (LaddersAndStairs.useObject(player, objectId, new Location(objectX, objectY, player.getLocation().getZ()), 2))
            {
                return;
            }
            switch (objectId)
            {
            case 28089:                 // GE desk
                Server.getGrandExchange().clickDesk(player, objectX, objectY, 2);
                break;

            case 25824:                 // Spinning wheel (Seers)
            case 36970:                 // Spinning wheel (Lumbridge
                Spinning.displaySpinningInterface(player);
                break;

            case 6:     // Dwarf multicannon
                DwarfCannon cannon = player.getCannon();
                Location    l      = new Location(objectX, objectY, player.getLocation().getZ());
                if (cannon == null || (cannon != null & !l.Equals(cannon.getLocation())))
                {
                    player.getPackets().sendMessage("This isn't your cannon!");
                    break;
                }
                cannon.pickupCannon();
                break;

            case 11666:                 // Falador furnace
            case 36956:                 // Lumbridge furnace
                Smelting.displaySmeltOptions(player);
                break;

            case 11959:                 // Tin rocks
            case 11958:
            case 11957:
            case 11933:
            case 11934:
            case 11935:
            case 31077:
            case 31078:
            case 31079:
                Mining.prospectRock(player, objectX, objectY, "tin");
                break;

            case 11960:                 // Copper rocks
            case 11961:
            case 11962:
            case 11936:
            case 11937:
            case 11938:
            case 31080:
            case 31081:
            case 31082:
                Mining.prospectRock(player, objectX, objectY, "copper");
                break;

            case 15504:                 // Clay rocks
            case 15503:
            case 15505:
            case 11189:
            case 11190:
            case 11191:
            case 31062:
            case 31063:
            case 31064:
            case 32429:
            case 32430:
            case 32431:
                Mining.prospectRock(player, objectX, objectY, "clay");
                break;

            case 11948:                 // Silver rocks
            case 11949:
            case 11950:
            case 11165:
            case 11186:
            case 11187:
            case 11188:
            case 31074:
            case 31075:
            case 31076:
            case 32444:
            case 32445:
            case 32446:
            case 15579:
            case 15580:
            case 15581:
                Mining.prospectRock(player, objectX, objectY, "silver");
                break;

            case 11930:                 // Coal rocks
            case 11931:
            case 11932:
            case 14850:
            case 14851:
            case 14852:
            case 31068:
            case 31069:
            case 31070:
            case 32426:
            case 32427:
            case 32428:
                Mining.prospectRock(player, objectX, objectY, "coal");
                break;

            case 11945:                 // Mithril rocks
            case 11946:
            case 11947:
            case 11942:
            case 11943:
            case 11944:
            case 14853:
            case 14854:
            case 14855:
            case 31086:
            case 31087:
            case 31088:
            case 32438:
            case 32439:
            case 32440:
                Mining.prospectRock(player, objectX, objectY, "mithril");
                break;

            case 11954:                 // Iron rocks
            case 11955:
            case 11956:
            case 14856:
            case 14857:
            case 14858:
            case 31071:
            case 31072:
            case 31073:
            case 32441:
            case 32442:
            case 32443:
                Mining.prospectRock(player, objectX, objectY, "iron");
                break;

            case 14859:                 // Rune rocks
            case 14860:
            case 14861:
                Mining.prospectRock(player, objectX, objectY, "runite");
                break;

            case 11951:                 // Gold rocks
            case 11952:
            case 11953:
            case 11183:
            case 11184:
            case 11185:
            case 31065:
            case 31066:
            case 31067:
            case 32432:
            case 32433:
            case 32434:
            case 15576:
            case 15577:
            case 15578:
                Mining.prospectRock(player, objectX, objectY, "gold");
                break;

            case 11963:                 // Adamant rocks
            case 11964:
            case 11965:
            case 11939:
            case 11940:
            case 11941:
            case 14862:
            case 14863:
            case 14864:
            case 31083:
            case 31084:
            case 31085:
            case 32435:
            case 32436:
            case 32437:
                Mining.prospectRock(player, objectX, objectY, "adamantite");
                break;

            case 11552:                 // Empty rocks
            case 11553:
            case 11554:
            case 11555:
            case 11556:
            case 31059:
            case 31060:
            case 31061:
            case 14832:
            case 14833:
            case 14834:
            case 33400:
            case 33401:
            case 33402:
            case 15582:
            case 15583:
            case 15584:
                Mining.displayEmptyRockMessage(player, new Location(objectX, objectY, player.getLocation().getZ()));
                break;

            case 2491:                 // Rune essence
                Mining.prospectRock(player, objectX, objectY, "Rune essence");
                break;

            case 27663:                 // Duel arena bank chest.
            case 2213:                  // Catherby bank booth.
            case 11402:                 // Varrock bank booth.
            case 11758:                 // Falador bank booth.
            case 36786:                 // Lumbridge bank booth.
            case 35647:                 // Al-Kharid bank booth.
            case 25808:                 // Seers bank booth.
            case 34752:                 // Ardougne bank booth.
            case 26972:                 // Edgeville bank booth.
            case 29085:                 // Ooglog bank booth.
                player.getBank().openBank(false, objectX, objectY);
                break;
            }
        }
Exemplo n.º 6
0
        internal override void show(TV tv)
        {
            WorldDate today = Utilities.Now();
            List <MiningPrediction> predictions = Mining.ListFloorsForDate(today);

            TemporaryAnimatedSprite background = loadBackground(tv, 0);
            TemporaryAnimatedSprite marlon     = loadPortrait(tv, "Marlon");
            TemporaryAnimatedSprite gil        = loadPortrait(tv, "Gil");

            // Opening scene: Marlon greets the viewer.
            queueScene(new Scene(Helper.Translation.Get((predictions.Count == 0)
                                ? "mining.opening.none" : "mining.opening"),
                                 background, marlon)
            {
                musicTrack = "MarlonsTheme"
            });

            // Marlon or Gil reports on each type of special floor.
            string joiner = CultureInfo.CurrentCulture.TextInfo.ListSeparator + " ";

            foreach (MineFloorType type in predictions
                     .Select((p) => p.type).Distinct().ToList())
            {
                List <int> floors = predictions
                                    .Where((p) => p.type == type)
                                    .Select((p) => p.floor)
                                    .ToList();
                string floorsText;
                if (floors.Count == 1)
                {
                    floorsText = Helper.Translation.Get("mining.floor",
                                                        new { num = floors[0] });
                }
                else
                {
                    int lastNum = floors[floors.Count - 1];
                    floors.RemoveAt(floors.Count - 1);
                    floorsText = Helper.Translation.Get("mining.floors",
                                                        new { nums = string.Join(joiner, floors), lastNum = lastNum });
                }

                queueScene(new Scene(Helper.Translation.Get($"mining.prediction.{type}",
                                                            new { floors = floorsText, }),
                                     loadBackground(tv, (int)type + 1),
                                     GilTypes.Contains(type) ? gil : marlon)
                {
                    musicTrack = "MarlonsTheme"
                });
            }

            // Closing scene: Marlon signs off.
            bool progress = Mining.IsProgressDependent;

            queueScene(new Scene
                           (Helper.Translation.Get($"mining.closing.{(progress? "progress" : "standard")}"),
                           background, marlon)
            {
                musicTrack = "MarlonsTheme"
            });

            runProgram(tv);
        }
Exemplo n.º 7
0
        public void Generate(IMetaWriter writer, Type type)
        {
            _writer = writer;
            _type   = type;

            writer.WriteLine("// iface - " + type.Name);
            //			writer.WriteLine("// all ifaces - " + string.Join(", ", Mining.GetAllIfaces(type).Distinct().Select(x => x.Name)));

            var members = type.GetMembers(BindingFlags.Public | BindingFlags.Instance).Concat(Mining.GetAllIfaces(type).Distinct().SelectMany(x => x.GetMembers())).ToArray();

//			if (!members.Any())
//			{
//				return;
//			}

            var names = GetTypeName(type);

            _typeShortName        = names.Name;
            _typeShortNameGeneric = names.NameGeneric;
            _typeFullNameGeneric  = names.FullNameGeneric;

            writer.WriteLine("public class {0} : {2} {1}", _typeShortNameGeneric, type.CSharpTypeIdentifier(), string.Format(BaseClass, type.CSharpTypeIdentifier()));
            writer.WriteLine("{");

            BeforeMembers();

            var methods = members.Where(x => x.MemberType == MemberTypes.Method).Cast <MethodInfo>().Where(x => !x.IsSpecialName).ToArray();

            foreach (var method in methods)
            {
                if (methods.Count(x => x.Name == method.Name) > 1 /* && method.ReturnType == typeof(object) */)                 // todo improve by comparing signature, not just name
                {
                    writer.Write("\t{0} {4}.{1}{2}({3})", method.ReturnType.CSharpTypeIdentifier(), method.Name, null, string.Join(", ", method.GetParameters().Select(x => x.CSharpTypeIdentifier() + " " + x.Name).ToArray()), method.DeclaringType.CSharpTypeIdentifier());
                }
                else
                {
                    writer.Write("\tpublic virtual {0} {1}{2}({3})", method.ReturnType.CSharpTypeIdentifier(), method.Name, null, string.Join(", ", method.GetParameters().Select(x => x.CSharpTypeIdentifier() + " " + x.Name).ToArray()));
                }


                writer.Write(" { ");
                WriteMethodBody(method);
                writer.WriteLine(" }");
            }

            foreach (var eventInfo in members.Where(x => x.MemberType == MemberTypes.Event).Cast <EventInfo>())
            {
                writer.Write("\tpublic virtual event {0} {1}", eventInfo.EventHandlerType.CSharpTypeIdentifier(), eventInfo.Name);
                writer.Write(" { ");
                writer.Write(" add { ");
                WriteEventSubscriber(eventInfo);
                writer.Write(" }");
                writer.Write(" remove { ");
                WriteEventUnsubscriber(eventInfo);
                writer.Write(" }");
                writer.WriteLine(" }");
            }

            var pros = members.Where(x => x.MemberType == MemberTypes.Property).Cast <PropertyInfo>().ToArray();

            foreach (var pro in pros)
            {
                var isIndexer = pro.GetIndexParameters().Any();

                var indexerParameters = string.Join(", ", pro.GetIndexParameters().Select(x => x.ParameterType.CSharpTypeIdentifier() + " " + x.Name).ToArray());
                indexerParameters = indexerParameters.Any() ? " [" + indexerParameters + "]" : null;

                var indexerArguments = string.Join(", ", pro.GetIndexParameters().Select(x => x.Name).ToArray());
                indexerArguments = indexerArguments.Any() ? "[" + indexerArguments + "]" : null;

                var myProName = isIndexer ? "this" : pro.Name;
                var orProName = isIndexer ? "" : "." + pro.Name;

                if (pros.Count(x => x.Name == pro.Name) > 1 /* && pro.PropertyType == typeof(object)*/)                // todo improve by comparing signature, not just name. +not just object but all except several obvious cases
                {
                    writer.Write("\t{0} {3}.{1}{2}", pro.PropertyType.CSharpTypeIdentifier(), myProName, indexerParameters, pro.DeclaringType.CSharpTypeIdentifier());
                }
                else
                {
                    writer.Write("\tpublic virtual {0} {1}{2}", pro.PropertyType.CSharpTypeIdentifier(), myProName, indexerParameters);
                }

                writer.Write(" { ");
                if (pro.CanRead)
                {
                    writer.Write(" get { ");
                    if (isIndexer)
                    {
                        WriteIndexerGetter(pro, indexerArguments);
                    }
                    else
                    {
                        WritePropertyGetter(pro);
                    }
                    writer.Write(" }");
                }
                if (pro.CanWrite)
                {
                    writer.Write(" set { ");
                    if (isIndexer)
                    {
                        WriteIndexerSetter(pro, indexerArguments);
                    }
                    else
                    {
                        WritePropertySetter(pro);
                    }
                    writer.Write(" }");
                }
                writer.WriteLine(" }");
            }

            writer.WriteLine("}");
        }
Exemplo n.º 8
0
        public void StartSystem()
        {
            if (isSystemStarted)
            {
                throw new InvalidOperationException("core_started");
            }

            ahdb      = new AccountHoldersDatabase(databaseBasepath);
            thdb      = new TransactionHistoriesDatabase(databaseBasepath);
            bcadb     = new BlockchainAccessDB(databaseBasepath);
            bmdb      = new BlockManagerDB(databaseBasepath);
            bdb       = new BlockDB(databaseBasepath);
            bfpdb     = new BlockFilePointersDB(databaseBasepath);
            ufadb     = new UtxoFileAccessDB(databaseBasepath);
            ufpdb     = new UtxoFilePointersDB(databaseBasepath);
            ufptempdb = new UtxoFilePointersTempDB(databaseBasepath);
            utxodb    = new UtxoDB(databaseBasepath);

            accountHolders        = new AccountHolders();
            accountHoldersFactory = new AccountHoldersFactory();

            byte[] ahDataBytes = ahdb.GetData();
            if (ahDataBytes.Length != 0)
            {
                accountHolders.FromBinary(ahDataBytes);
            }
            else
            {
                accountHolders.LoadVersion0();
            }

            transactionHistories = thdb.GetData().Pipe((data) => data.Length == 0 ? new TransactionHistories() : SHAREDDATA.FromBinary <TransactionHistories>(data));
            transactionHistories.UnconfirmedTransactionAdded += (sender, e) =>
            {
                foreach (var accountHolder in accountHolders.AllAccountHolders)
                {
                    foreach (var account in accountHolder.Accounts)
                    {
                        foreach (var prevTxOut in e.senders)
                        {
                            if (account.Address.Equals(prevTxOut.Address))
                            {
                                account.accountStatus.unconfirmedAmount = new CurrencyUnit(account.accountStatus.unconfirmedAmount.rawAmount + prevTxOut.Amount.rawAmount);
                            }
                        }
                    }
                }
            };
            transactionHistories.UnconfirmedTransactionRemoved += (sender, e) =>
            {
                foreach (var accountHolder in accountHolders.AllAccountHolders)
                {
                    foreach (var account in accountHolder.Accounts)
                    {
                        foreach (var prevTxOut in e.receivers)
                        {
                            if (account.Address.Equals(prevTxOut.Address))
                            {
                                account.accountStatus.unconfirmedAmount = new CurrencyUnit(account.accountStatus.unconfirmedAmount.rawAmount - prevTxOut.Amount.rawAmount);
                            }
                        }
                    }
                }
            };

            usableBalanceCache = new CachedData <CurrencyUnit>(() =>
            {
                long rawAmount = 0;
                foreach (var accountHolder in accountHolders.AllAccountHolders)
                {
                    foreach (var account in accountHolder.Accounts)
                    {
                        rawAmount += account.accountStatus.usableAmount.rawAmount;
                    }
                }
                return(new CurrencyUnit(rawAmount));
            });
            unusableBalanceCache = new CachedData <CurrencyUnit>(() =>
            {
                long rawAmount = 0;
                foreach (var accountHolder in accountHolders.AllAccountHolders)
                {
                    foreach (var account in accountHolder.Accounts)
                    {
                        rawAmount += account.accountStatus.unusableAmount.rawAmount;
                    }
                }
                return(new CurrencyUnit(rawAmount));
            });
            unconfirmedBalanceCache = new CachedData <CurrencyUnit>(() =>
            {
                long rawAmount = 0;
                foreach (var accountHolder in accountHolders.AllAccountHolders)
                {
                    foreach (var account in accountHolder.Accounts)
                    {
                        rawAmount += account.accountStatus.unconfirmedAmount.rawAmount;
                    }
                }
                return(new CurrencyUnit(rawAmount));
            });
            usableBalanceWithUnconfirmedCache   = new CachedData <CurrencyUnit>(() => new CurrencyUnit(usableBalanceCache.Data.rawAmount - unconfirmedBalanceCache.Data.rawAmount));
            unusableBalanceWithUnconformedCache = new CachedData <CurrencyUnit>(() => new CurrencyUnit(unusableBalanceCache.Data.rawAmount + unconfirmedBalanceCache.Data.rawAmount));

            blockChain = new BlockChain(bcadb, bmdb, bdb, bfpdb, ufadb, ufpdb, ufptempdb, utxodb);
            blockChain.LoadTransactionHistories(transactionHistories);

            //<未改良>暫定?
            if (blockChain.headBlockIndex == -1)
            {
                blockChain.UpdateChain(new GenesisBlock());

                this.RaiseNotification("genesis_block_generated", 5);
            }

            Dictionary <Account, EventHandler <Tuple <CurrencyUnit, CurrencyUnit> > > changeAmountDict = new Dictionary <Account, EventHandler <Tuple <CurrencyUnit, CurrencyUnit> > >();

            Action <bool> _UpdateBalance = (isOnlyUnconfirmed) =>
            {
                if (!isOnlyUnconfirmed)
                {
                    usableBalanceCache.IsModified   = true;
                    unusableBalanceCache.IsModified = true;
                }
                unconfirmedBalanceCache.IsModified             = true;
                usableBalanceWithUnconfirmedCache.IsModified   = true;
                unusableBalanceWithUnconformedCache.IsModified = true;

                BalanceUpdated(this, EventArgs.Empty);
            };

            Action <Account, bool> _AddAddressEvent = (account, isUpdatebalance) =>
            {
                EventHandler <Tuple <CurrencyUnit, CurrencyUnit> > eh = (sender, e) =>
                {
                    account.accountStatus.usableAmount   = e.Item1;
                    account.accountStatus.unusableAmount = e.Item2;
                };

                changeAmountDict.Add(account, eh);

                AddressEvent addressEvent = new AddressEvent(account.Address.Hash);
                addressEvent.BalanceUpdated += eh;

                blockChain.AddAddressEvent(addressEvent);

                long rawAmount = 0;
                foreach (var unconfirmedTh in transactionHistories.unconfirmedTransactionHistories.ToArray())
                {
                    foreach (var prevTxOut in unconfirmedTh.senders)
                    {
                        if (prevTxOut.Address.Equals(account.Address))
                        {
                            rawAmount += prevTxOut.Amount.rawAmount;
                        }
                    }
                }
                account.accountStatus.unconfirmedAmount = new CurrencyUnit(rawAmount);

                if (isUpdatebalance)
                {
                    _UpdateBalance(false);
                }
            };

            EventHandler <Account> _AccountAdded = (sender, e) =>
            {
                utxodb.Open();

                _AddAddressEvent(e, true);

                utxodb.Close();
            };
            EventHandler <Account> _AccountRemoved = (sender, e) =>
            {
                EventHandler <Tuple <CurrencyUnit, CurrencyUnit> > eh = changeAmountDict[e];

                changeAmountDict.Remove(e);

                AddressEvent addressEvent = blockChain.RemoveAddressEvent(e.Address.Hash);
                addressEvent.BalanceUpdated -= eh;

                _UpdateBalance(false);
            };

            utxodb.Open();

            foreach (var accountHolder in accountHolders.AllAccountHolders)
            {
                foreach (var account in accountHolder.Accounts)
                {
                    _AddAddressEvent(account, false);
                }

                accountHolder.AccountAdded   += _AccountAdded;
                accountHolder.AccountRemoved += _AccountRemoved;
            }

            utxodb.Close();

            accountHolders.AccountHolderAdded += (sender, e) =>
            {
                e.AccountAdded   += _AccountAdded;
                e.AccountRemoved += _AccountRemoved;
            };
            accountHolders.AccountHolderRemoved += (semder, e) =>
            {
                e.AccountAdded   -= _AccountAdded;
                e.AccountRemoved -= _AccountRemoved;
            };

            blockChain.BalanceUpdated += (sender, e) => _UpdateBalance(false);

            _UpdateBalance(false);

            unconfirmedTtxs    = new Dictionary <TransferTransaction, TransactionOutput[]>();
            mining             = new Mining();
            mining.FoundNonce += (sender, e) => creaNodeTest.DiffuseNewBlock(e);

            blockChain.Updated += (sender, e) =>
            {
                foreach (var block in e)
                {
                    foreach (var tx in block.Transactions)
                    {
                        foreach (var txIn in tx.TxInputs)
                        {
                            TransferTransaction contradiction = null;

                            foreach (var unconfirmedTx in unconfirmedTtxs)
                            {
                                foreach (var unconfirmedTxIn in unconfirmedTx.Key.TxInputs)
                                {
                                    if (txIn.PrevTxBlockIndex == unconfirmedTxIn.PrevTxBlockIndex && txIn.PrevTxIndex == unconfirmedTxIn.PrevTxIndex && txIn.PrevTxOutputIndex == unconfirmedTxIn.PrevTxOutputIndex)
                                    {
                                        contradiction = unconfirmedTx.Key;

                                        break;
                                    }
                                }

                                if (contradiction != null)
                                {
                                    break;
                                }
                            }

                            if (contradiction != null)
                            {
                                unconfirmedTtxs.Remove(contradiction);
                            }
                        }
                    }
                }

                Mine();
            };

            Mine();

            //creaNodeTest = new CreaNode(ps.NodePort, creaVersion, appnameWithVersion, new FirstNodeInfosDatabase(p2pDirectory));
            creaNodeTest = new CreaNodeTest(blockChain, ps.NodePort, creaVersion, appnameWithVersion);
            creaNodeTest.ConnectionKeeped       += (sender, e) => creaNodeTest.SyncronizeBlockchain();
            creaNodeTest.ReceivedNewTransaction += (sender, e) =>
            {
                TransferTransaction ttx = e as TransferTransaction;

                if (ttx == null)
                {
                    return;
                }

                TransactionOutput[] prevTxOuts = new TransactionOutput[ttx.TxInputs.Length];
                for (int i = 0; i < prevTxOuts.Length; i++)
                {
                    prevTxOuts[i] = blockChain.GetMainBlock(ttx.TxInputs[i].PrevTxBlockIndex).Transactions[ttx.TxInputs[i].PrevTxIndex].TxOutputs[ttx.TxInputs[i].PrevTxOutputIndex];
                }

                if (!ttx.Verify(prevTxOuts))
                {
                    return;
                }

                List <TransactionOutput> senders   = new List <TransactionOutput>();
                List <TransactionOutput> receivers = new List <TransactionOutput>();

                long sentAmount     = 0;
                long receivedAmount = 0;

                for (int i = 0; i < ttx.txInputs.Length; i++)
                {
                    foreach (var accountHolder in accountHolders.AllAccountHolders)
                    {
                        foreach (var account in accountHolder.Accounts)
                        {
                            if (prevTxOuts[i].Address.Equals(account.Address.Hash))
                            {
                                sentAmount += prevTxOuts[i].Amount.rawAmount;

                                senders.Add(prevTxOuts[i]);
                            }
                        }
                    }
                }

                for (int i = 0; i < ttx.TxOutputs.Length; i++)
                {
                    foreach (var accountHolder in accountHolders.AllAccountHolders)
                    {
                        foreach (var account in accountHolder.Accounts)
                        {
                            if (ttx.TxOutputs[i].Address.Equals(account.Address.Hash))
                            {
                                receivedAmount += ttx.TxOutputs[i].Amount.rawAmount;

                                receivers.Add(ttx.TxOutputs[i]);
                            }
                        }
                    }
                }

                if (senders.Count > 0 || receivers.Count > 0)
                {
                    TransactionHistoryType type = TransactionHistoryType.transfered;
                    if (receivers.Count < ttx.TxOutputs.Length)
                    {
                        type = TransactionHistoryType.sent;
                    }
                    else if (senders.Count < ttx.TxInputs.Length)
                    {
                        type = TransactionHistoryType.received;
                    }

                    transactionHistories.AddTransactionHistory(new TransactionHistory(true, false, type, DateTime.MinValue, 0, ttx.Id, senders.ToArray(), receivers.ToArray(), ttx, prevTxOuts, new CurrencyUnit(sentAmount), new CurrencyUnit(receivedAmount - sentAmount)));
                }

                utxodb.Open();

                for (int i = 0; i < ttx.TxInputs.Length; i++)
                {
                    if (blockChain.FindUtxo(prevTxOuts[i].Address, ttx.TxInputs[i].PrevTxBlockIndex, ttx.TxInputs[i].PrevTxIndex, ttx.TxInputs[i].PrevTxOutputIndex) == null)
                    {
                        return;
                    }
                }

                utxodb.Close();

                foreach (var txIn in ttx.TxInputs)
                {
                    foreach (var unconfirmedTtx in unconfirmedTtxs)
                    {
                        foreach (var unconfirmedTxIn in unconfirmedTtx.Key.TxInputs)
                        {
                            if (txIn.PrevTxBlockIndex == unconfirmedTxIn.PrevTxBlockIndex && txIn.PrevTxIndex == unconfirmedTxIn.PrevTxIndex && txIn.PrevTxOutputIndex == unconfirmedTxIn.PrevTxOutputIndex)
                            {
                                return;
                            }
                        }
                    }
                }

                unconfirmedTtxs.Add(ttx, prevTxOuts);

                Mine();
            };
            creaNodeTest.ReceivedNewBlock += (sender, e) => blockChain.UpdateChain(e).Pipe((ret) => this.RaiseResult("blockchain_update", 5, ret.ToString()));
            //creaNodeTest.Start();

            isSystemStarted = true;
        }