コード例 #1
0
        //private void shouldgo()
        //{
        //    Go = true;
        //}

        //protected void Back(bool reallygo)
        //{
        //    if (reallygo)
        //        shouldgo();

        //    if (positionY == maxout && Go && !done)
        //    {
        //        if (Map.Instance.Name.ToString() == "MainMap")
        //        {
        //            //this.OnDetach();
        //            ////Controls.Add(new MainMenuWindow());
        //            //MainMenuWindow.Instance.Go = false;
        //            //done = true;
        //            this.OnDetach();
        //            Controls.Add(new MPAKlobbyWindow());
        //            done = true;
        //        }
        //        else
        //        {
        //            //SetShouldDetach();
        //        }
        //    }
        //}

        #endregion overrides

        private void UpdateVariantCost(int amountToAdd)
        {
            variantCost = 0;

            if (amountToAdd != -1)
            {
                AKunitType akt = spawner.Spawned.Type as AKunitType;
                for (int i = 0; i < akt.BodyParts.Count; i++)
                {
                    TextBlock bodyPartBlock = variant.FindChild(akt.BodyParts[i].GUIDesplayName);

                    if (bodyPartBlock != null)
                    {
                        int bodyPartIndex      = i;
                        int bodyPartBlockIndex = variant.Children.IndexOf(bodyPartBlock);

                        AKunitType.BodyPart bodyPart = akt.BodyParts[i];

                        for (int j = 0; j < bodyPart.Weapons.Count; j++)
                        {
                            TextBlock bodyPartWeaponBlock =
                                bodyPartBlock.FindChild(bodyPart.Weapons[j].MapObjectAlias);

                            if (bodyPartWeaponBlock != null)
                            {
                                int alternateWeaponIndex = int.Parse(bodyPartWeaponBlock.Attributes[0].Value);

                                variantCost += bodyPart.Weapons[j].Alternates[alternateWeaponIndex].Price;
                            }
                        }
                    }
                }
            }

            UpdateCashText();
        }
コード例 #2
0
        private void btnBuy_Click(Button sender)
        {
            //find hangar for what we are trying to spawn

            Hangar selectedHangar = null;

            if (currentList == MechDBUnits)
            {
                selectedHangar = mechHangar;
            }

            if (currentList == GDBUnits)
            {
                selectedHangar = groundUnitHangar;
            }

            if (currentList == ADBUnits)
            {
                selectedHangar = airUnitHangar;
            }

            if (currentList == JDBUnits)
            {
                selectedHangar = jetHangar;
            }

            string un = currentPriceList.Type.PriceLists[
                int.Parse(SelectedB.Controls["RelatedUnitID"].Text)].PricedUnit.Name;

            UnitType ut = (UnitType)EntityTypes.Instance.GetByName(un);

            TextBlock variant = null;

            if (variantList.SelectedIndex > 0)
            {
                string varName = string.Format("{0}\\Variants\\{1}\\{2}",
                                               VirtualFileSystem.UserDirectoryPath, ut.Name, variantList.SelectedItem.ToString());

                variant = TextBlockUtils.LoadFromRealFile(varName);
            }

            //parse TextBlock to int[] so it can be networked more efficiently

            AKunitType akt = ut as AKunitType;

            int[]  varData       = null;
            string varDataString = string.Empty;

            if (variant != null)
            {
                //calculate the elements needed for the compressed variant data
                {
                    int elementCount = 0;
                    foreach (TextBlock c in variant.Children)
                    {
                        elementCount += c.Children.Count;
                    }

                    elementCount *= 4;

                    varData = new int[elementCount];
                }

                int x = 0;
                for (int i = 0; i < akt.BodyParts.Count; i++)
                {
                    TextBlock bodyPartBlock = variant.FindChild(akt.BodyParts[i].GUIDesplayName);

                    if (bodyPartBlock != null)
                    {
                        int bodyPartIndex      = i;
                        int bodyPartBlockIndex = variant.Children.IndexOf(bodyPartBlock);

                        AKunitType.BodyPart bodyPart = akt.BodyParts[i];

                        for (int j = 0; j < bodyPart.Weapons.Count; j++)
                        {
                            TextBlock bodyPartWeaponBlock =
                                bodyPartBlock.FindChild(bodyPart.Weapons[j].MapObjectAlias);

                            if (bodyPartWeaponBlock != null)
                            {
                                int bodyPartWeaponIndex = j;

                                int alternateWeaponIndex = int.Parse(bodyPartWeaponBlock.Attributes[0].Value);
                                int fireGroup            = int.Parse(bodyPartWeaponBlock.Attributes[1].Value);
                                varData[x]     = bodyPartIndex;
                                varData[x + 1] = bodyPartWeaponIndex;
                                varData[x + 2] = alternateWeaponIndex;
                                varData[x + 3] = fireGroup;

                                if (varDataString != string.Empty)
                                {
                                    varDataString += ":";
                                }

                                varDataString += string.Format("{0}:{1}:{2}:{3}",
                                                               bodyPartIndex, bodyPartWeaponIndex, alternateWeaponIndex, fireGroup);
                                x += 4;
                            }
                        }
                    }
                }
            }

            if (EntitySystemWorld.Instance.IsClientOnly())
            {
                selectedHangar.Client_SendSpawnRequestToServer(ut.Name, varDataString);
            }
            else
            {
                selectedHangar.SpawnNewUnit(ut, varData);
            }

            SetShouldDetach();
        }