Esempio n. 1
0
        private void LoadLife(Wz_Node lifeNode)
        {
            bool isCategory   = lifeNode.Nodes["isCategory"].GetValueEx <int>(0) != 0;
            var  lifeNodeList = !isCategory ? lifeNode.Nodes : lifeNode.Nodes.SelectMany(n => n.Nodes);

            int i = 0;

            foreach (var node in lifeNodeList)
            {
                var item = LifeItem.LoadFromNode(node);
                if (isCategory)
                {
                    item.Name  = $"life_{item.Type}_{node.ParentNode.Text}_{node.Text}";
                    item.Index = i++;
                }
                else
                {
                    item.Name  = $"life_{item.Type}_{node.Text}";
                    item.Index = int.Parse(node.Text);
                }

                //直接绑定foothold
                ContainerNode <FootholdItem> fhNode;
                if (item.Fh != 0 && (fhNode = FindFootholdByID(item.Fh)) != null)
                {
                    fhNode.Slots.Add(item);
                }
                else
                {
                    Scene.Fly.Sky.Slots.Add(item);
                }
            }
        }
        internal Rectangle?GetLifeBoundingBox(LifeItem life)
        {
            if (life.View.Animator is StateMachineAnimator animator)
            {
                try
                {
                    var data = (StateMachineAnimator.FrameStateMachineData)animator.Data;
                    IDictionary <string, RepeatableFrameAnimationData> dict = data.Data;
                    string currentState = data.SelectedState;
                    int    currentFrame = (animator.Data as StateMachineAnimator.FrameStateMachineData)
                                          .FrameAnimator
                                          .CurrentFrameIndex;
                    var raw = dict[currentState].Frames[currentFrame].BoundingBox.Value;
                    return(new Rectangle(life.X - (raw.Width / 2),
                                         life.Cy - raw.Height,
                                         raw.Width,
                                         raw.Height));
                }
                catch (Exception e) when(e is NullReferenceException || e is KeyNotFoundException ||
                                         e is IndexOutOfRangeException || e is InvalidOperationException)
                {
                    return(null);
                }
            }

            return(null);
        }
        private void UpdateBoundingBox(LifeItem life)
        {
            if (_boundingBoxPoints == null)
            {
                return;
            }
            var boundingBox = GetLifeBoundingBox(life);

            if (boundingBox.HasValue)
            {
                var width  = boundingBox.Value.Width;
                var height = boundingBox.Value.Height;
                var x      = boundingBox.Value.X;
                var y      = boundingBox.Value.Y;

                _boundingBoxPoints.Add(new Point(x, y));
                _boundingBoxPoints.Add(new Point(x + width, y));

                _boundingBoxPoints.Add(new Point(x + width, y));
                _boundingBoxPoints.Add(new Point(x + width, y + height));

                _boundingBoxPoints.Add(new Point(x + width, y + height));
                _boundingBoxPoints.Add(new Point(x, y + height));

                _boundingBoxPoints.Add(new Point(x, y + height));
                _boundingBoxPoints.Add(new Point(x, y));
            }
        }
Esempio n. 4
0
        private TooltipContent DrawItem(GameTime gameTime, RenderEnv env, LifeItem item)
        {
            var     blocks = new List <TextBlock>();
            Vector2 size   = Vector2.Zero;

            blocks = new List <TextBlock>();
            StringResult sr      = null;
            Vector2      current = Vector2.Zero;

            switch (item.Type)
            {
            case LifeItem.LifeType.Mob:
            {
                this.StringLinker?.StringMob.TryGetValue(item.ID, out sr);
                blocks.Add(PrepareTextBlock(env.Fonts.TooltipTitleFont, sr == null ? "(null)" : sr.Name, ref current, Color.LightYellow));
                current += new Vector2(4, 4);
                blocks.Add(PrepareTextBlock(env.Fonts.TooltipContentFont, "id:" + item.ID.ToString("d7"), ref current, Color.White));
                size.X  = Math.Max(size.X, current.X);
                current = new Vector2(0, current.Y + 16);

                Vector2 size2;
                var     blocks2 = TooltipHelper.Prepare(item.LifeInfo, env.Fonts, out size2);
                for (int i = 0; i < blocks2.Length; i++)
                {
                    blocks2[i].Position.Y += current.Y;
                    blocks.Add(blocks2[i]);
                }
                size.X = Math.Max(size.X, size2.X);
                size.Y = current.Y + size2.Y;
            }
            break;

            case LifeItem.LifeType.Npc:
            {
                this.StringLinker?.StringNpc.TryGetValue(item.ID, out sr);
                blocks.Add(PrepareTextBlock(env.Fonts.TooltipTitleFont, sr == null ? "(null)" : sr.Name, ref current, Color.LightYellow));
                current += new Vector2(4, 4);
                blocks.Add(PrepareTextBlock(env.Fonts.TooltipContentFont, "id:" + item.ID.ToString("d7"), ref current, Color.White));
                size.X  = Math.Max(size.X, current.X);
                current = new Vector2(0, current.Y + 16);

                var aniName = (item.View?.Animator as StateMachineAnimator)?.GetCurrent();
                if (aniName != null)
                {
                    blocks.Add(PrepareTextLine(env.Fonts.TooltipContentFont, "action: " + aniName, ref current, Color.White, ref size.X));
                }

                size.Y = current.Y;
            }
            break;
            }

            return(new TooltipContent()
            {
                blocks = blocks, size = size
            });
        }
Esempio n. 5
0
        private MeshItem GetMeshLife(LifeItem life)
        {
            var renderObj = GetRenderObject(life.View.Animator);

            return(renderObj == null ? null : new MeshItem()
            {
                RenderObject = renderObj,
                Position = new Vector2(life.X, life.Cy),
                FlipX = life.Flip,
                Z0 = ((renderObj as Frame)?.Z ?? 0),
                Z1 = life.Index,
            });
        }
Esempio n. 6
0
        private MeshItem GetMeshLife(LifeItem life)
        {
            var renderObj = GetRenderObject(life.View.Animator);

            if (renderObj == null)
            {
                return(null);
            }
            var mesh = batcher.MeshPop();

            mesh.RenderObject = renderObj;
            mesh.Position     = new Vector2(life.X, life.Cy);
            mesh.FlipX        = life.Flip;
            mesh.Z0           = ((renderObj as Frame)?.Z ?? 0);
            mesh.Z1           = life.Index;
            return(mesh);
        }
Esempio n. 7
0
        private void LoadLife(Wz_Node lifeNode)
        {
            foreach (var node in lifeNode.Nodes)
            {
                var item = LifeItem.LoadFromNode(node);
                item.Name  = $"life_{item.Type}_{node.Text}";
                item.Index = int.Parse(node.Text);

                //直接绑定foothold
                ContainerNode <FootholdItem> fhNode;
                if (item.Fh != 0 && (fhNode = FindFootholdByID(item.Fh)) != null)
                {
                    fhNode.Slots.Add(item);
                }
                else
                {
                    Scene.Fly.Sky.Slots.Add(item);
                }
            }
        }
Esempio n. 8
0
        private void PreloadResource(ResourceLoader resLoader, LifeItem life)
        {
            string path;

            switch (life.Type)
            {
            case LifeItem.LifeType.Mob:
                path = $@"Mob\{life.ID:D7}.img";
                var mobNode = PluginManager.FindWz(path);

                //加载mob数据
                if (mobNode != null)
                {
                    life.LifeInfo = LifeInfo.CreateFromNode(mobNode);
                }

                //获取link
                int?mobLink = mobNode?.FindNodeByPath(@"info\link").GetValueEx <int>();
                if (mobLink != null)
                {
                    path    = $@"Mob\{mobLink.Value:D7}.img";
                    mobNode = PluginManager.FindWz(path);
                }

                //加载动画
                if (mobNode != null)
                {
                    var aniItem = this.CreateSMAnimator(mobNode, resLoader);
                    if (aniItem != null)
                    {
                        AddMobAI(aniItem);
                        life.View = new LifeItem.ItemView()
                        {
                            Animator = aniItem
                        };
                    }
                }
                break;

            case LifeItem.LifeType.Npc:
                path = $@"Npc\{life.ID:D7}.img";
                var npcNode = PluginManager.FindWz(path);

                //TODO: 加载npc数据
                int?npcLink = npcNode?.FindNodeByPath(@"info\link").GetValueEx <int>();
                if (npcLink != null)
                {
                    path    = $@"Npc\{npcLink.Value:D7}.img";
                    npcNode = PluginManager.FindWz(path);
                }

                //加载动画
                if (npcNode != null)
                {
                    var aniItem = this.CreateSMAnimator(npcNode, resLoader);
                    if (aniItem != null)
                    {
                        AddNpcAI(aniItem);
                        life.View = new LifeItem.ItemView()
                        {
                            Animator = aniItem
                        };
                    }
                }
                break;
            }

            if (life.View == null) //空动画
            {
                life.View = new LifeItem.ItemView();
            }
        }
Esempio n. 9
0
        public void Load(IRace selectedPlayerRace)
        {
            //TODO implement diff levels //-> pass as parameter in methed the level create sweatch for levels and set for mapPath diff map resourse

            var mapPath = AppSettings.MapLevel1;
            var frientFactory = new FriendFactory();
            var enemyFactory = new EnemyFactory();

            this.PlayerRace = selectedPlayerRace;
            var width = AppSettings.MapElementSize.Width;
            var height = AppSettings.MapElementSize.Height;

            try
            {
                using (var reader = new StreamReader(mapPath))
                {
                    for (var row = 0; row < AppSettings.MapElementsCountY; row++)
                    {
                        var top = (row*height)+AppSettings.MapPosition.Top;

                        var line = reader.ReadLine();
                        for (var col = 0; col < AppSettings.MapElementsCountX; col++)
                        {
                            var left = col*width;

                            var currentsymbol = line[col];
                            switch (currentsymbol)
                            {
                                case 'p':
                                    this.Player = new Player(this.PlayerRace)
                                    {
                                        Position = new Position (left, top),
                                        Size = new Size(width, height)
                                    };
                                    break;

                                case 'f':
                                    this.Friend = (Friend)frientFactory.Create(_friendRace);
                                    this.Friend.Position = new Position(left, top);
                                    this.Friend.Size = new Size(width, height);
                                    break;

                                case 'e':
                                    var enemy = (Enemy)enemyFactory.Create(_enemyRace);
                                    enemy.Position = new Position (left, top);
                                    enemy.Size = new Size(width, height);
                                    this.Enemies.Add(enemy);
                                    break;

                                case 'w':
                                    var mazeElement = new MazeItem()
                                    {
                                        Position = new Position(left, top),
                                        Size = new Size(width, height)
                                    };
                                    this.Maze.Add(mazeElement);
                                    break;

                                case 'b':
                                    var beer = new BeerItem()
                                    {
                                        Position = new Position(left, top),
                                        Size = new Size(width, height)
                                    };
                                    this.ItemToCollect.Add(beer);
                                    break;

                                case 'l':
                                    var itemLife = new LifeItem()
                                    {
                                        Position = new Position(left, top),
                                        Size = new Size(width, height)
                                    };
                                    this.ItemToCollect.Add(itemLife);
                                    break;

                                case 'h':
                                    var itemHealth = new LargeHealthItem()
                                    {
                                        Position = new Position(left, top),
                                        Size = new Size(width, height)
                                    };
                                    this.ItemToCollect.Add(itemHealth);
                                    break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "BB Game MapLoader");
            }
        }