示例#1
0
 public HighlightVoxelsVisualizer(IVoxelHandle handle, Func <IVoxelHandle, IEnumerable <IVoxelHandle> > getHighlights)
 {
     this.getHighlights = getHighlights;
     // WARNING: cannot keep handle because it can be shared across voxels!!
     // IDEA: should autoconvert between the gameplay voxel type and the rendering voxel type
     this.handle = handle.GetInternalVoxel();
 }
示例#2
0
        /// <summary>
        /// Should pass the correct voxel (with correct x and y coord)
        /// </summary>
        public void ToVoxel(GameVoxel voxel, GameplayObjectsSerializer gameplayObjectsSerializer)
        {
            Debug.Assert(voxel.Coord.X == X);
            Debug.Assert(voxel.Coord.Y == Y);


            voxel.World.ChangeType(voxel, gameplayObjectsSerializer.GetVoxelType(this.TypeName));
            //voxel.ResetData(); // TODO: potential overhead

            //voxel.Data.Type = gameplayObjectsSerializer.GetVoxelType(this.TypeName);
            voxel.Data.MagicLevel = MagicLevel;
            voxel.Data.DataValue  = DataValue;


            voxel.Data.Inventory.Clear();
            if (InventoryItems != null)
            {
                foreach (var item in InventoryItems)
                {
                    voxel.Data.Inventory.AddNewItems(gameplayObjectsSerializer.GetItemType(item), 1);
                }
            }

            voxel.Data.Height      = Height;
            voxel.Data.WorkerCount = WorkerCount;
        }
 public void OnKeyPressed(GameVoxel target, Key key)
 {
     transporter.Send(new UserInputHandlerPacket("OnKeyPressed", target.Coord)
     {
         Key = (int)key
     });
 }
        private void updateSelectedVoxelVisualizers()
        {
            var voxel = inputSim.GetTargetedVoxel();

            if (voxel != visualizedVoxel || (voxel != null && voxel.Type != visualizedType))
            {
                foreach (var v in visualizers)
                {
                    v.Hide();
                }
                visualizers.Clear();

                visualizedVoxel = null;
                visualizedType  = null;
                if (voxel != null && voxel.Type != null)
                {
                    visualizedVoxel = voxel;
                    visualizedType  = voxel.Type;
                    visualizers.AddRange(voxel.Type.GetInfoVisualizers(voxel));
                    foreach (var v in visualizers)
                    {
                        v.Show();
                    }
                }
            }

            foreach (var v in visualizers)
            {
                v.Update();
            }
        }
 public RangeVisualizer(IVoxelHandle handle, int range)
 {
     // WARNING: cannot keep handle because it can be shared across voxels!!
     // IDEA: should autoconvert between the gameplay voxel type and the rendering voxel type
     this.handle = handle.GetInternalVoxel();
     this.range  = range;
 }
示例#6
0
        public InventoryVisualizer(IVoxelHandle handle)
        {
            // WARNING: cannot keep handle because it can be shared across voxels!!
            // IDEA: should autoconvert between the gameplay voxel type and the rendering voxel type
            this.handle = handle.GetInternalVoxel();

            ItemRelativeTransformationProvider = i => getItemCircleTransformation(i, this.handle, 1);
        }
示例#7
0
 public void RegisterAdjacentChange(GameVoxel target, Action <GameVoxel> func)
 {
     if (changeActions.ContainsKey(target))
     {
         throw new InvalidOperationException("Can only register one handler");
     }
     changeActions.Add(target, func);
 }
        public void OnRightClick(GameVoxel target)
        {
            if (tryVoxelInteract(target))
            {
                return;
            }

            ActivePlayerTool.OnRightClick(player, target);
        }
        public ValueControlVisualizer(IVoxelHandle handle, Func <int> getValue, Action <int> setValue, Matrix local)
        {
            this.getValue = getValue;
            this.setValue = setValue;
            this.local    = local;
            ValueControl  = new ValueControl();

            voxel = handle.GetInternalVoxel();
        }
示例#10
0
        public static Matrix getItemCircleTransformation(int i, GameVoxel targetVoxel, float radiusScale)
        {
            var radius = targetVoxel.GetBoundingBox().Maximum.X - targetVoxel.GetBoundingBox().Minimum.X;

            radius *= radiusScale;
            var angle = MathHelper.TwoPi / targetVoxel.Data.Inventory.ItemCount * i;

            return(Matrix.Translation(new Vector3(Math.Cos(angle).ToF(), 0.5f, Math.Sin(angle).ToF()) * radius));
        }
        private IMesh getMesh(GameVoxel gameVoxel)
        {
            if (gameVoxel.Type == null)
            {
                return(null);
            }

            var handle = gameVoxel;

            return(gameVoxel.Type.GetMesh(handle));
        }
        private void showDataValueRect(GameVoxel target, int value)
        {
            var max = target.GetBoundingBox().Maximum;
            var min = target.GetBoundingBox().Minimum;
            var pos = (max + min) * 0.5f + new Vector3(0, 6.5f, 0);

            dataValueRectangle.Position    = pos;
            dataValueRectangle.IsBillboard = true;
            dataValueRectangle.Text        = value.ToString();// target.DataValue.ToString();
            dataValueRectangle.Radius      = 3;
            dataValueRectangle.Update();
        }
示例#13
0
        private void destroyRenderdata(GameVoxel removed)
        {
            if (!visualizers.ContainsKey(removed))
            {
                return;
            }
            foreach (var viz in visualizers[removed].Visualizers)
            {
                viz.Hide();
            }

            visualizers.Remove(removed);
        }
示例#14
0
        public override void OnRightClick(PlayerState player, IVoxelHandle voxel)
        {
            int radius = 3;

            if (prevVoxel != null)
            {
                prevVoxel.GetRangeCircle(radius).ForEach(v => v.Data.MagicLevel = 0);
            }

            var handle = voxel;

            handle.GetRangeCircle(radius).Where(v => v.Type is InfestationVoxelType).ForEach(removeInfestation);
            prevVoxel = voxel.GetInternalVoxel();
        }
示例#15
0
        public static SerializedVoxel FromVoxel(GameVoxel voxel)
        {
            var ret = new SerializedVoxel();

            ret.DataValue      = voxel.Data.DataValue;
            ret.MagicLevel     = voxel.Data.MagicLevel;
            ret.TypeName       = voxel.Type.Name;
            ret.X              = voxel.Coord.X;
            ret.Y              = voxel.Coord.Y;
            ret.InventoryItems = voxel.Data.Inventory.Items.Select(i => i.Name).ToArray();
            ret.Height         = voxel.Data.Height;
            ret.WorkerCount    = voxel.Data.WorkerCount;

            return(ret);
        }
示例#16
0
        private void createRenderData(GameVoxel added)
        {
            var vizs = added.Type.GetCustomVisualizers(added).ToArray();

            if (!vizs.Any())
            {
                return;
            }
            foreach (var v in vizs)
            {
                v.Show();
            }

            visualizers[added] = new RenderData(vizs, added.Type);
        }
示例#17
0
        public void Setup()
        {
            var builder = new ContainerBuilder();

            builder.RegisterModule <OfflineGameModule>();
            builder.RegisterType <Internal.Model.World>().SingleInstance().AsSelf()
            .OnActivating(args =>
            {
                args.Instance.Initialize(10, 10);

                var land = args.Context.Resolve <LandType>();
                args.Instance.ForEach((v, p) => v.ChangeType(land));
            });


            var cont = builder.Build();

            var offline = cont.Resolve <GodGameOffline>();

            offline.AddSimulatorsToEngine(EngineFactory.CreateEngine());
            world = offline.World;
            types = cont.Resolve <VoxelTypesFactory>();
            items = cont.Resolve <ItemTypesFactory>();

            basicFactory    = new GenericVoxelType <BasicFactory>(v => new BasicFactory(v));
            constantFactory = new GenericVoxelType <ConstantFactory>(v => new ConstantFactory(v));
            pusher          = new GenericVoxelType <Pusher>(v => new Pusher(v));
            puller          = new GenericVoxelType <Puller>(v => new Puller(v));

            v55 = world.GetVoxel(new Point2(5, 5));
            v56 = world.GetVoxel(new Point2(5, 6));
            v57 = world.GetVoxel(new Point2(5, 7));

            v46 = world.GetVoxel(new Point2(4, 6));
            v36 = world.GetVoxel(new Point2(3, 6));
        }
示例#18
0
 private IVoxelHandle haxorIVoxelHandelize(IVoxelHandle callingVoxel, GameVoxel voxel)
 {
     return(voxel);
 }
 public void OnTargetChanged(GameVoxel target)
 {
     throw new System.NotImplementedException();
 }
示例#20
0
 public TargetedItem(GameVoxel source, ItemType itemType, GameVoxel destination)
 {
     Source      = source;
     ItemType    = itemType;
     Destination = destination;
 }
 public void OnLeftClick(GameVoxel target)
 {
     transporter.Send(new UserInputHandlerPacket("OnLeftClick", target.Coord));
 }
        private bool tryVoxelInteract(GameVoxel target)
        {
            var ret = target.Type.Interact(target);

            return(ret);
        }
示例#23
0
 public void UnRegisterAdjacentChange(GameVoxel target)
 {
     changeActions.Remove(target);
 }
 public void OnLeftClick(GameVoxel target)
 {
     ActivePlayerTool.OnLeftClick(player, target);
 }
 public void OnTargetChanged(GameVoxel target)
 {
     ActivePlayerTool.OnTargetChanged(player, target, TW.Graphics.Keyboard, TW.Graphics.Mouse);
 }
 public void OnKeyPressed(GameVoxel target, Key key)
 {
     ActivePlayerTool.OnKeypress(player, target, key);
 }