示例#1
0
        public CreatureGeoInfo AddCreature(Creature _creature, Point _worldCoords, Point _liveCoords, WorldLayer _layer = null)
        {
            if (_creature is FakedCreature)
            {
                _creature = (Creature)((FakedCreature)_creature).Essence.Clone(World.TheWorld.Avatar);
            }

            if (InfoByCreature.ContainsKey(_creature))
            {
                throw new ApplicationException();
            }

            if (_layer == null)
            {
                _layer = World.TheWorld.Avatar.GeoInfo.Layer;
            }

            CreatureGeoInfo geoInfo;

            if (!OutOfScope.TryGetValue(_creature, out geoInfo))
            {
                geoInfo = new CreatureGeoInfo(_creature, _worldCoords)
                {
                    Layer = _layer
                };
            }
            else
            {
                OutOfScope.Remove(_creature);
            }

            InfoByCreature.Add(_creature, geoInfo);

            PointByCreature.Add(geoInfo, _worldCoords);
            if (_creature is AbstractDummyCreature)
            {
                List <CreatureGeoInfo> list;
                if (!DummyCreatureByPoint.TryGetValue(_worldCoords, out list))
                {
                    list = new List <CreatureGeoInfo>();
                    DummyCreatureByPoint.Add(_worldCoords, list);
                }
                list.Add(geoInfo);
            }
            else
            {
                CreatureByPoint.Add(_worldCoords, geoInfo);
            }

            geoInfo.LiveCoords = _liveCoords;

            _creature.GeoInfo = geoInfo;
            geoInfo[0, 0].ResetCached();

            if (_creature.GeoInfo.WorldCoords != _worldCoords)
            {
                throw new ApplicationException();
            }

            return(geoInfo);
        }
示例#2
0
        public void MoveCreature(Creature _creature, Point _worldCoord, WorldLayer _layer = null)
        {
            if (_layer == null)
            {
                _layer = World.TheWorld.Avatar.GeoInfo.Layer;
            }

            _creature[0, 0].ResetCached();

            var info = InfoByCreature[_creature];

            if (_creature.GeoInfo.WorldCoords != info.WorldCoords)
            {
                throw new ApplicationException();
            }

            if (_layer != info.Layer)
            {
                if (_creature.IsAvatar)
                {
                    //Если аватар ушел на другой уровень
                    var allCreatures = InfoByCreature.Keys.ToArray();
                    foreach (var creature in allCreatures)
                    {
                        if (creature.IsAvatar)
                        {
                            continue;
                        }
                        if (creature is AbstractDummyCreature)
                        {
                            CreatureIsDead(creature);
                        }
                        else
                        {
                            ExcludeCreature(creature);
                        }
                    }
                    info.Layer = _layer;
                    World.TheWorld.LiveMap.Reset();
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            else
            {
                if (info.WorldCoords == _worldCoord)
                {
                    throw new ApplicationException();
                }

                PointByCreature.Remove(info);

                var oldBlockId = BaseMapBlock.GetBlockId(info.WorldCoords);
                var newBlockId = BaseMapBlock.GetBlockId(_worldCoord);

                var delta = _worldCoord - info.WorldCoords;
                if (oldBlockId != newBlockId)
                {
                    var newCell = info[delta];
                    if (_creature.IsAvatar)
                    {
                        World.TheWorld.LiveMap.AvatarChangesBlock(oldBlockId, newBlockId, newCell.LiveMapBlock.LiveMapBlockId);
                    }
                }
                if (info.LiveCoords != null)
                {
                    if (_creature is AbstractDummyCreature)
                    {
                        if (!DummyCreatureByPoint[info.WorldCoords].Remove(info))
                        {
                            throw new ApplicationException();
                        }
                        List <CreatureGeoInfo> list;
                        if (!DummyCreatureByPoint.TryGetValue(_worldCoord, out list))
                        {
                            list = new List <CreatureGeoInfo>();
                            DummyCreatureByPoint.Add(_worldCoord, list);
                        }
                        list.Add(info);
                    }
                    else
                    {
                        if (!CreatureByPoint.Remove(info.WorldCoords))
                        {
                            throw new ApplicationException();
                        }
                        CreatureByPoint.Add(_worldCoord, info);
                    }
                    info.LiveCoords += delta;
                    info.WorldCoords = _worldCoord;

                    PointByCreature.Add(info, _worldCoord);
                }
            }
            if (info.LiveCoords != null)
            {
                _creature[0, 0].ResetCached();
                if (_creature.IsAvatar)
                {
                    MessageManager.SendMessage(this, WorldMessage.AvatarMove);
                }
            }
        }