Пример #1
0
        private void MapFieldItem_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            //Title = DB.NotifyCounter.ToString();
            //DB.NotifyCounter = 0;
            //if (VM.SelectedMapField != null)
            //  VM.SelectedMapField.Update();
            Border   border = (Border)sender;
            MapField field  = (MapField)border.Tag;

            if (AutoBtnChkBx.IsChecked.Value && AutoBtnList.SelectedItem != null)
            {
                Country country = (Country)AutoBtnList.SelectedItem;
                if (AutoFieldBtnChkBx.IsChecked.Value)
                {
                    field.Owner = country.Number;
                    VM.UpdateCityOwner(field.Idx, country.Number);
                    field.Update();
                }
                else
                {
                    foreach (var fieldTemp in VM.WorldFields)
                    {
                        if (fieldTemp.ProvinceId == field.ProvinceId && fieldTemp.IsSea == field.IsSea)
                        {
                            fieldTemp.Owner = country.Number;
                            if (fieldTemp.IsSea == false)
                            {
                                VM.UpdateCityOwner(fieldTemp.Idx, country.Number);
                            }
                            fieldTemp.Update();
                        }
                    }
                }
            }
            else
            {
                if (VM.SelectedMapField != null)
                {
                    VM.SelectedMapField.IsSelected = false;
                }
                VM.SelectedMapField = field;
                //VM.SelectedMapField.RawData[22] = 5;
                //VM.SelectedMapField.Update();

                VM.RowItem.Clear();
                VM.RowItem.Add(VM.SelectedMapField);

                if (FieldDetailsDataGrid.Columns.Count == 0)
                {
                    int columnIndex = 0;
                    foreach (var data in VM.SelectedMapField.RawData)
                    {
                        FieldDetailsDataGrid.Columns.Add(
                            new DataGridTextColumn
                        {
                            Header   = DB.HEADERS[columnIndex],
                            MinWidth = 30,
                            Binding  = new Binding(string.Format("RawData[{0}]", columnIndex))
                            {
                                NotifyOnTargetUpdated = true
                            }
                        });
                        columnIndex++;
                    }
                }
                //FieldDetailsDataGrid.ItemsSource = VM.RowItem;
                VM.SelectedMapField.IsSelected = true;
            }
        }
Пример #2
0
 private static bool HasPreciousResource(MapField field)
 {
     return(field.RawData[DB.LAND_TYPE_RES] >= 24 && field.RawData[DB.LAND_TYPE_RES] <= 27);
 }
Пример #3
0
        private void LoadWorldMap()
        {
            while (true)
            {
                loadIdx++;
                if (RawData[loadIdx] == 26)
                {
                    //world map data starts 14 bytes after 1A 03 00 0C 03
                    if (RawData[loadIdx + 1] == 3 && RawData[loadIdx + 2] == 0 && RawData[loadIdx + 3] == 12 && RawData[loadIdx + 4] == 3)
                    {
                        mapKeyIdx         = loadIdx + 20;
                        MapKey            = GetValueString(mapKeyIdx, RawData[loadIdx + 19]);
                        loadIdx          += 20 + RawData[loadIdx + 19];
                        mapFieldsStartIdx = loadIdx;
                        break;
                        //Can we verify map key anyhow?
                        //if (Regex.IsMatch(MapKey, @"^[a-zA-Z0-9]{3,29}$")) break;
                    }
                }
            }

            WorldFields = new MapField[6480];
            MapField field;
            int      fieldsInRowCount = 1;
            int      currentRow       = 1;
            int      worldIndex       = 0;

            while (true)
            {
                field = new MapField
                {
                    RawData = GetXBytes(loadIdx, 40),
                    Idx     = (short)worldIndex
                };

                if (HasValue(field.RawData, 255) == false)
                {
                    loadIdx++; break;
                }

                field.Row        = currentRow;
                field.Col        = fieldsInRowCount;
                field.ProvinceId = field.RawData[23] == 255 ? field.RawData[5] : field.RawData[23];

                if (worldIndex > 1)
                {
                    if (WorldFields[worldIndex - 1].ProvinceId != field.ProvinceId)
                    {
                        Thickness newBorder = field.Border;
                        newBorder.Left = 1;
                        field.Border   = newBorder;
                    }

                    if (worldIndex > 108)
                    {
                        if (field.Row % 2 == 0)
                        {
                            if (WorldFields[worldIndex - 108].ProvinceId != field.ProvinceId)
                            {
                                field.TopLeftBorder = Visibility.Visible;
                            }

                            if (WorldFields[worldIndex - 107].ProvinceId != field.ProvinceId)
                            {
                                field.TopRightBorder = Visibility.Visible;
                            }
                        }
                        else
                        {
                            if (WorldFields[worldIndex - 108].ProvinceId != field.ProvinceId)
                            {
                                field.TopRightBorder = Visibility.Visible;
                            }

                            if (WorldFields[worldIndex - 109].ProvinceId != field.ProvinceId)
                            {
                                field.TopLeftBorder = Visibility.Visible;
                            }
                        }
                    }
                }

                field.Update();
                WorldFields[worldIndex] = field;
                worldIndex++;
                fieldsInRowCount++;

                if (fieldsInRowCount == 109)
                {
                    currentRow++;
                    fieldsInRowCount = 1;
                }
                loadIdx += 40;
                field    = null;
            }
            WorldSize = WorldFields.Length;
        }
Пример #4
0
 private static bool IsNotExplorable(MapField field)
 {
     return(field.RawData[DB.LAND_TYPE_GFX] < 8 || field.RawData[DB.LAND_TYPE_GFX] > 11);
 }