示例#1
0
        private static NativeObject BuildDebuggableObject(XaeiOSObject xaeiosObject, VTable vtable, IntRef fieldCounter)
        {
            NativeObject debuggableObject = new NativeObject();

            // add fields from base class
            // update field counter along the way so that we know which slots correspond to which field names
            if (vtable != GetSystemObjectVTable())
            {
                debuggableObject[DebugBaseKey] = var.Cast<NativeObject>(BuildDebuggableObject(
                    xaeiosObject,
                    vtable.BaseVTable,
                    fieldCounter
                ));
            }

            // retreive debug information for class through vtable
            VTableDebugInfo debugInfo = vtable.DebugInfo;

            // apply debug information to object instance
            {
                debuggableObject["FullName"] = var.Cast<string>(debugInfo.FullName);

                // fields
                NativeArray<string> fieldNames = debugInfo.Fields;
                for (int i = 0; i < fieldNames.Length; i++)
                {
                    debuggableObject[fieldNames[i]] = xaeiosObject[fieldCounter.Value + i];
                }
                fieldCounter.Value += fieldNames.Length;
            }

            return debuggableObject;
        }
 public void DrawItemInfo(int screenposX, int screenposY, Packet_Item item)
 {
     int sizex = dataItems.ItemSizeX(item);
     int sizey = dataItems.ItemSizeY(item);
     IntRef tw = new IntRef();
     IntRef th = new IntRef();
     float one = 1;
     game.platform.TextSize(dataItems.ItemInfo(item), 11 + one / 2, tw, th);
     tw.value += 6;
     th.value += 4;
     int w = game.platform.FloatToInt(tw.value + CellDrawSize * sizex);
     int h = game.platform.FloatToInt(th.value < CellDrawSize * sizey ? CellDrawSize * sizey + 4 : th.value);
     if (screenposX < w + 20) { screenposX = w + 20; }
     if (screenposY < h + 20) { screenposY = h + 20; }
     if (screenposX > game.Width() - (w + 20)) { screenposX = game.Width() - (w + 20); }
     if (screenposY > game.Height() - (h + 20)) { screenposY = game.Height() - (h + 20); }
     game.Draw2dTexture(game.WhiteTexture(), screenposX - w, screenposY - h, w, h, null, 0, Game.ColorFromArgb(255, 0, 0, 0), false);
     game.Draw2dTexture(game.WhiteTexture(), screenposX - w + 2, screenposY - h + 2, w - 4, h - 4, null, 0, Game.ColorFromArgb(255, 105, 105, 105), false);
     FontCi font = new FontCi();
     font.family = "Arial";
     font.size = 10;
     game.Draw2dText(dataItems.ItemInfo(item), font, screenposX - tw.value + 4, screenposY - h + 2, null, false);
     Packet_Item item2 = new Packet_Item();
     item2.BlockId = item.BlockId;
     DrawItem(screenposX - w + 2, screenposY - h + 2, item2, 0, 0);
 }
 public override bool OnClientCommand(Game game, ClientCommandArgs args)
 {
     if (args.command == "fps")
     {
         IntRef argumentsLength = new IntRef();
         string[] arguments = m.GetPlatform().StringSplit(args.arguments, " ", argumentsLength);
         if (m.GetPlatform().StringTrim(args.arguments) == "")
         {
             drawfpstext = true;
         }
         else if (arguments[0] == "1")
         {
             drawfpstext = true;
             drawfpsgraph = false;
         }
         else if (arguments[0] == "2")
         {
             drawfpstext = true;
             drawfpsgraph = true;
         }
         else
         {
             drawfpstext = false;
             drawfpsgraph = false;
         }
         return true;
     }
     return false;
 }
示例#4
0
 internal void DrawScreenshotFlash(Game game)
 {
     game.Draw2dTexture(game.WhiteTexture(), 0, 0, game.platform.GetCanvasWidth(), game.platform.GetCanvasHeight(), null, 0, Game.ColorFromArgb(255, 255, 255, 255), false);
     string screenshottext = "&0Screenshot";
     IntRef textWidth = new IntRef();
     IntRef textHeight = new IntRef();
     game.platform.TextSize(screenshottext, 50, textWidth, textHeight);
     FontCi font = new FontCi();
     font.family = "Arial";
     font.size = 50;
     game.Draw2dText(screenshottext, font, game.xcenter(textWidth.value), game.ycenter(textHeight.value), null, false);
 }
示例#5
0
 public int[] GetOnTable(Vector3IntRef[] table, int tableCount, IntRef retCount)
 {
     int[] ontable = new int[2048];
     int ontableCount = 0;
     for (int i = 0; i < tableCount; i++)
     {
         Vector3IntRef v = table[i];
         int t = d_Map.GetBlock(v.X, v.Y, v.Z + 1);
         ontable[ontableCount++] = t;
     }
     retCount.value = ontableCount;
     return ontable;
 }
示例#6
0
    public BlockPosSide[] LineIntersection(DelegateIsBlockEmpty isEmpty, DelegateGetBlockHeight getBlockHeight, Line3D line, IntRef retCount)
    {
        lCount = 0;
        currentLine = line;
        currentHit[0] = 0;
        currentHit[1] = 0;
        currentHit[2] = 0;
        ListBox3d l1 = Search(PredicateBox3DHit.Create(this));
        for (int i = 0; i < l1.count; i++)
        {
            Box3D node = l1.arr[i];
            float[] hit = currentHit;
            float x = node.MinEdge[0];
            float y = node.MinEdge[2];
            float z = node.MinEdge[1];
            if (!isEmpty.IsBlockEmpty(platform.FloatToInt(x),platform.FloatToInt(y),platform.FloatToInt( z)))
            {
                Box3D node2 = new Box3D();
                node2.MinEdge = Vec3.CloneIt(node.MinEdge);
                node2.MaxEdge = Vec3.CloneIt(node.MaxEdge);
                node2.MaxEdge[1] = node2.MinEdge[1] + getBlockHeight.GetBlockHeight(platform.FloatToInt(x),platform.FloatToInt(y),platform.FloatToInt(z));

                BlockPosSide b = new BlockPosSide();
                float[] hit2 = new float[3];

                float[] dir = new float[3];
                dir[0] = line.End[0] - line.Start[0];
                dir[1] = line.End[1] - line.Start[1];
                dir[2] = line.End[2] - line.Start[2];
                bool ishit = Intersection.HitBoundingBox(node2.MinEdge, node2.MaxEdge, line.Start, dir, hit2);
                if (ishit)
                {
                    //hit2.pos = Vec3.FromValues(x, z, y);
                    b.blockPos = Vec3.FromValues(platform.FloatToInt(x), platform.FloatToInt(z), platform.FloatToInt(y));
                    b.collisionPos = hit2;
                    l[lCount++] = b;
                }
            }
        }
        BlockPosSide[] ll = new BlockPosSide[lCount];
        for (int i = 0; i < lCount; i++)
        {
            ll[i] = l[i];
        }
        retCount.value = lCount;
        return ll;
    }
示例#7
0
 public Vector3IntRef[] GetTable(int posx, int posy, int posz, IntRef retCount)
 {
     Vector3IntRef[] l = new Vector3IntRef[2048];
     int lCount = 0;
     Vector3IntRef[] todo = new Vector3IntRef[2048];
     int todoCount = 0;
     todo[todoCount++] = Vector3IntRef.Create(posx, posy, posz);
     for (; ; )
     {
         if (todoCount == 0 || lCount >= maxcraftingtablesize)
         {
             break;
         }
         Vector3IntRef p = todo[todoCount - 1];
         todoCount--;
         if (Vector3IntRefArrayContains(l, lCount, p))
         {
             continue;
         }
         l[lCount++] = p;
         Vector3IntRef a = Vector3IntRef.Create(p.X + 1, p.Y, p.Z);
         if (d_Map.GetBlock(a.X, a.Y, a.Z) == d_Data.BlockIdCraftingTable())
         {
             todo[todoCount++] = a;
         }
         Vector3IntRef b = Vector3IntRef.Create(p.X - 1, p.Y, p.Z);
         if (d_Map.GetBlock(b.X, b.Y, b.Z) == d_Data.BlockIdCraftingTable())
         {
             todo[todoCount++] = b;
         }
         Vector3IntRef c = Vector3IntRef.Create(p.X, p.Y + 1, p.Z);
         if (d_Map.GetBlock(c.X, c.Y, c.Z) == d_Data.BlockIdCraftingTable())
         {
             todo[todoCount++] = c;
         }
         Vector3IntRef d = Vector3IntRef.Create(p.X, p.Y - 1, p.Z);
         if (d_Map.GetBlock(d.X, d.Y, d.Z) == d_Data.BlockIdCraftingTable())
         {
             todo[todoCount++] = d;
         }
     }
     retCount.value = lCount;
     return l;
 }
    float[] tmpPlayerPosition; //Temporarily stores the player's position. Used in WallSlide()

    #endregion Fields

    #region Constructors

    public ScriptCharacterPhysics()
    {
        movedz = 0;
        curspeed = new Vector3Ref();
        jumpacceleration = 0;
        isplayeronground = false;
        acceleration = new Acceleration();
        jumpstartacceleration = 0;
        jumpstartaccelerationhalf = 0;
        movespeednow = 0;

        tmpPlayerPosition = new float[3];
        tmpBlockingBlockType = new IntRef();

        constGravity = 0.3f;
        constWaterGravityMultiplier = 3;
        constEnableAcceleration = true;
        constJump = 2.1f;
    }
示例#9
0
 public static byte[] Serialize(Packet_Server packet, IntRef retLength)
 {
     CitoMemoryStream ms = new CitoMemoryStream();
     Packet_ServerSerializer.Serialize(ms, packet);
     byte[] data = ms.ToArray();
     retLength.value = ms.Length();
     return data;
 }
示例#10
0
 public abstract string[] StringSplit(string value, string separator, IntRef returnLength);
示例#11
0
 public abstract void TextSize(string text, float fontSize, IntRef outWidth, IntRef outHeight);
示例#12
0
    public static string StringSubstring(GamePlatform p, string a, int start, int count)
    {
        IntRef aLength = new IntRef();
        int[] aChars = p.StringToCharArray(a, aLength);

        int[] bChars = new int[count];
        for (int i = 0; i < count; i++)
        {
            bChars[i] = aChars[start + i];
        }
        return p.CharArrayToString(bChars, count);
    }
示例#13
0
    public override void OnNewFrameDraw2d(Game game, float deltaTime)
    {
        if (game.guistate != GuiState.MapLoading)
        {
            return;
        }

        GamePlatform platform = game.platform;
        float        one      = 1;

        Width  = platform.GetCanvasWidth();
        Height = platform.GetCanvasHeight();
        DrawBackground(game);

        string connecting = game.language.Connecting();

        if (game.issingleplayer && (!platform.SinglePlayerServerLoaded()))
        {
            connecting = "Starting game...";
        }
        if (game.maploadingprogress.ProgressStatus != null)
        {
            connecting = game.maploadingprogress.ProgressStatus;
        }

        if (game.invalidVersionDrawMessage != null)
        {
            game.Draw2dText(game.invalidVersionDrawMessage, game.fontMapLoading, game.xcenter(game.TextSizeWidth(game.invalidVersionDrawMessage, game.fontMapLoading)), Height / 2 - 50, null, false);
            string connect = "Click to connect";
            game.Draw2dText(connect, game.fontMapLoading, game.xcenter(game.TextSizeWidth(connect, game.fontMapLoading)), Height / 2 + 50, null, false);
            return;
        }

        IntRef serverNameWidth  = new IntRef();
        IntRef serverNameHeight = new IntRef();

        platform.TextSize(game.ServerInfo.ServerName, game.fontMapLoading, serverNameWidth, serverNameHeight);
        game.Draw2dText(game.ServerInfo.ServerName, game.fontMapLoading, game.xcenter(serverNameWidth.value), Height / 2 - 150, null, false);

        if (game.ServerInfo.ServerMotd != null)
        {
            IntRef serverMotdWidth  = new IntRef();
            IntRef serverMotdHeight = new IntRef();
            platform.TextSize(game.ServerInfo.ServerMotd, game.fontMapLoading, serverMotdWidth, serverMotdHeight);
            game.Draw2dText(game.ServerInfo.ServerMotd, game.fontMapLoading, game.xcenter(serverMotdWidth.value), Height / 2 - 100, null, false);
        }

        IntRef connectingWidth  = new IntRef();
        IntRef connectingHeight = new IntRef();

        platform.TextSize(connecting, game.fontMapLoading, connectingWidth, connectingHeight);
        game.Draw2dText(connecting, game.fontMapLoading, game.xcenter(connectingWidth.value), Height / 2 - 50, null, false);

        string progress  = platform.StringFormat(game.language.ConnectingProgressPercent(), platform.IntToString(game.maploadingprogress.ProgressPercent));
        string progress1 = platform.StringFormat(game.language.ConnectingProgressKilobytes(), platform.IntToString(game.maploadingprogress.ProgressBytes / 1024));

        if (game.maploadingprogress.ProgressPercent > 0)
        {
            IntRef progressWidth  = new IntRef();
            IntRef progressHeight = new IntRef();
            platform.TextSize(progress, game.fontMapLoading, progressWidth, progressHeight);
            game.Draw2dText(progress, game.fontMapLoading, game.xcenter(progressWidth.value), Height / 2 - 20, null, false);

            IntRef progress1Width  = new IntRef();
            IntRef progress1Height = new IntRef();
            platform.TextSize(progress1, game.fontMapLoading, progress1Width, progress1Height);
            game.Draw2dText(progress1, game.fontMapLoading, game.xcenter(progress1Width.value), Height / 2 + 10, null, false);

            float progressratio = one * game.maploadingprogress.ProgressPercent / 100;
            int   sizex         = 400;
            int   sizey         = 40;
            game.Draw2dTexture(game.WhiteTexture(), game.xcenter(sizex), Height / 2 + 70, sizex, sizey, null, 0, Game.ColorFromArgb(255, 0, 0, 0), false);
            int   red    = Game.ColorFromArgb(255, 255, 0, 0);
            int   yellow = Game.ColorFromArgb(255, 255, 255, 0);
            int   green  = Game.ColorFromArgb(255, 0, 255, 0);
            int[] colors = new int[3];
            colors[0] = red;
            colors[1] = yellow;
            colors[2] = green;
            int c = InterpolationCi.InterpolateColor(platform, progressratio, colors, 3);
            game.Draw2dTexture(game.WhiteTexture(), game.xcenter(sizex), Height / 2 + 70, progressratio * sizex, sizey, null, 0, c, false);
        }
    }
示例#14
0
 public abstract string[] StringSplit(string value, string separator, IntRef returnLength);
示例#15
0
 public static IntRef Create(int value_)
 {
     IntRef intref = new IntRef();
     intref.value = value_;
     return intref;
 }
示例#16
0
    public BlockPosSide[] LineIntersection(DelegateIsBlockEmpty isEmpty, DelegateGetBlockHeight getBlockHeight, Line3D line, IntRef retCount)
    {
        lCount        = 0;
        currentLine   = line;
        currentHit[0] = 0;
        currentHit[1] = 0;
        currentHit[2] = 0;
        ListBox3d l1 = Search(PredicateBox3DHit.Create(this));

        for (int i = 0; i < l1.count; i++)
        {
            Box3D   node = l1.arr[i];
            float[] hit  = currentHit;
            float   x    = node.MinEdge[0];
            float   y    = node.MinEdge[2];
            float   z    = node.MinEdge[1];
            if (!isEmpty.IsBlockEmpty(platform.FloatToInt(x), platform.FloatToInt(y), platform.FloatToInt(z)))
            {
                Box3D node2 = new Box3D();
                node2.MinEdge    = Vec3.CloneIt(node.MinEdge);
                node2.MaxEdge    = Vec3.CloneIt(node.MaxEdge);
                node2.MaxEdge[1] = node2.MinEdge[1] + getBlockHeight.GetBlockHeight(platform.FloatToInt(x), platform.FloatToInt(y), platform.FloatToInt(z));

                BlockPosSide b    = new BlockPosSide();
                float[]      hit2 = new float[3];

                float[] dir = new float[3];
                dir[0] = line.End[0] - line.Start[0];
                dir[1] = line.End[1] - line.Start[1];
                dir[2] = line.End[2] - line.Start[2];
                bool ishit = Intersection.HitBoundingBox(node2.MinEdge, node2.MaxEdge, line.Start, dir, hit2);
                if (ishit)
                {
                    //hit2.pos = Vec3.FromValues(x, z, y);
                    b.blockPos     = Vec3.FromValues(platform.FloatToInt(x), platform.FloatToInt(z), platform.FloatToInt(y));
                    b.collisionPos = hit2;
                    l[lCount++]    = b;
                }
            }
        }
        BlockPosSide[] ll = new BlockPosSide[lCount];
        for (int i = 0; i < lCount; i++)
        {
            ll[i] = l[i];
        }
        retCount.value = lCount;
        return(ll);
    }
示例#17
0
    /// <summary>
    /// Split a given string into words with different colors
    /// </summary>
    /// <param name="s">String to split</param>
    /// <param name="defaultcolor">Default color to use when no color code is given</param>
    /// <param name="retLength"><see cref="IntRef"/> the number of text parts will be written to</param>
    /// <returns><see cref="TextPart"/> array containing the processed parts of the given string</returns>
    public TextPart[] DecodeColors(string s, int defaultcolor, IntRef retLength)
    {
        // Maximum word/message length
        int messageMax = 256;
        int wordMax    = 64;

        // Prepare temporary arrays
        TextPart[] parts      = new TextPart[messageMax];
        int        partsCount = 0;

        int[] currenttext       = new int[wordMax];
        int   currenttextLength = 0;
        bool  endCurrentWord    = false;

        // Split the given string into single characters
        IntRef sLength = new IntRef();

        int[] sChars = platform.StringToCharArray(s, sLength);

        // Set default color
        int  currentColor = defaultcolor;
        bool changeColor  = false;
        int  nextColor    = defaultcolor;

        // Process each character
        for (int i = 0; i < sLength.value; i++)
        {
            if (partsCount >= messageMax)
            {
                // Quit parsing text if message has reached maximum length
                break;
            }

            if (endCurrentWord || currenttextLength >= wordMax)
            {
                if (currenttextLength > 0)
                {
                    //Add content so far to return value
                    TextPart part = new TextPart();
                    part.text         = platform.CharArrayToString(currenttext, currenttextLength);
                    part.color        = currentColor;
                    parts[partsCount] = part;
                    partsCount++;
                    currenttextLength = 0;
                }
                endCurrentWord = false;
            }

            if (changeColor)
            {
                currentColor = nextColor;
                changeColor  = false;
            }

            if (sChars[i] == ' ')
            {
                // Begin a new word if a space character is found
                currenttext[currenttextLength] = sChars[i];
                currenttextLength++;
                endCurrentWord = true;
            }
            else if (sChars[i] == '&')
            {
                // If a & is found, try to parse a color code
                if (i + 1 < sLength.value)
                {
                    int color = HexToInt(sChars[i + 1]);
                    if (color != -1)
                    {
                        // Update current color and end word
                        nextColor      = GetColor(color);
                        changeColor    = true;
                        endCurrentWord = true;

                        // Increment i to prevent the code from being read again
                        i++;

                        continue;
                    }
                    else
                    {
                        // No valid color code found. Display as normal character
                        currenttext[currenttextLength] = sChars[i];
                        currenttextLength++;
                    }
                }
                else
                {
                    // End of string. Display as normal character
                    currenttext[currenttextLength] = sChars[i];
                    currenttextLength++;
                }
            }
            else
            {
                // Nothing special. Just add the current character
                currenttext[currenttextLength] = sChars[i];
                currenttextLength++;
            }
        }

        // Add any leftover text parts in current color
        if (currenttextLength != 0 && partsCount < messageMax)
        {
            TextPart part = new TextPart();
            part.text         = platform.CharArrayToString(currenttext, currenttextLength);
            part.color        = currentColor;
            parts[partsCount] = part;
            partsCount++;
        }

        // Set length of returned array and return result
        retLength.value = partsCount;
        return(parts);
    }
示例#18
0
    internal void CraftingMouse(Game game)
    {
        if (currentRecipes == null)
        {
            return;
        }
        int menustartx = game.xcenter(600);
        int menustarty = game.ycenter(currentRecipesCount * 80);

        if (game.mouseCurrentY >= menustarty && game.mouseCurrentY < menustarty + currentRecipesCount * 80)
        {
            craftingselectedrecipe = (game.mouseCurrentY - menustarty) / 80;
        }
        else
        {
            //craftingselectedrecipe = -1;
        }
        if (game.mouseleftclick)
        {
            if (currentRecipesCount != 0)
            {
                CraftingRecipeSelected(game, craftingTableposx, craftingTableposy, craftingTableposz, IntRef.Create(currentRecipes[craftingselectedrecipe]));
            }
            game.mouseleftclick = false;
            game.GuiStateBackToGame();
        }
    }
示例#19
0
    internal void DrawCraftingRecipes(Game game)
    {
        currentRecipes      = new int[1024];
        currentRecipesCount = 0;
        for (int i = 0; i < craftingrecipes2Count; i++)
        {
            Packet_CraftingRecipe r = craftingrecipes2[i];
            if (r == null)
            {
                continue;
            }
            bool next = false;
            //can apply recipe?
            for (int k = 0; k < r.IngredientsCount; k++)
            {
                Packet_Ingredient ingredient = r.Ingredients[k];
                if (ingredient == null)
                {
                    continue;
                }
                if (craftingblocksFindAllCount(craftingblocks, craftingblocksCount, ingredient.Type) < ingredient.Amount)
                {
                    next = true;
                    break;
                }
            }
            if (!next)
            {
                currentRecipes[currentRecipesCount++] = i;
            }
        }
        int menustartx = game.xcenter(600);
        int menustarty = game.ycenter(currentRecipesCount * 80);

        if (currentRecipesCount == 0)
        {
            game.Draw2dText(game.language.NoMaterialsForCrafting(), fontCraftingGui, game.xcenter(200), game.ycenter(20), null, false);
            return;
        }
        for (int i = 0; i < currentRecipesCount; i++)
        {
            Packet_CraftingRecipe r = craftingrecipes2[currentRecipes[i]];
            for (int ii = 0; ii < r.IngredientsCount; ii++)
            {
                int xx = menustartx + 20 + ii * 130;
                int yy = menustarty + i * 80;
                game.Draw2dTexture(game.d_TerrainTextures.terrainTexture(), xx, yy, 32, 32, IntRef.Create(game.TextureIdForInventory[r.Ingredients[ii].Type]), game.texturesPacked(), Game.ColorFromArgb(255, 255, 255, 255), false);
                game.Draw2dText(game.platform.StringFormat2("{0} {1}", game.platform.IntToString(r.Ingredients[ii].Amount), game.blocktypes[r.Ingredients[ii].Type].Name), fontCraftingGui, xx + 50, yy,
                                IntRef.Create(i == craftingselectedrecipe ? Game.ColorFromArgb(255, 255, 0, 0) : Game.ColorFromArgb(255, 255, 255, 255)), false);
            }
            {
                int xx = menustartx + 20 + 400;
                int yy = menustarty + i * 80;
                game.Draw2dTexture(game.d_TerrainTextures.terrainTexture(), xx, yy, 32, 32, IntRef.Create(game.TextureIdForInventory[r.Output.Type]), game.texturesPacked(), Game.ColorFromArgb(255, 255, 255, 255), false);
                game.Draw2dText(game.platform.StringFormat2("{0} {1}", game.platform.IntToString(r.Output.Amount), game.blocktypes[r.Output.Type].Name), fontCraftingGui, xx + 50, yy,
                                IntRef.Create(i == craftingselectedrecipe ? Game.ColorFromArgb(255, 255, 0, 0) : Game.ColorFromArgb(255, 255, 255, 255)), false);
            }
        }
    }
示例#20
0
 public override void InventoryClick(Packet_InventoryPosition pos)
 {
     if (pos.Type == Packet_InventoryPositionTypeEnum.MainArea)
     {
         Point?selected = null;
         foreach (var k in d_Inventory.Items)
         {
             if (pos.AreaX >= k.Key.X && pos.AreaY >= k.Key.Y &&
                 pos.AreaX < k.Key.X + d_Items.ItemSizeX(k.Value) &&
                 pos.AreaY < k.Key.Y + d_Items.ItemSizeY(k.Value))
             {
                 selected = new Point(k.Key.X, k.Key.Y);
             }
         }
         //drag
         if (selected != null && d_Inventory.DragDropItem == null)
         {
             d_Inventory.DragDropItem = d_Inventory.Items[new ProtoPoint(selected.Value.X, selected.Value.Y)];
             d_Inventory.Items.Remove(new ProtoPoint(selected.Value.X, selected.Value.Y));
             SendInventory();
         }
         //drop
         else if (d_Inventory.DragDropItem != null)
         {
             //make sure there is nothing blocking drop.
             IntRef     itemsAtAreaCount = new IntRef();
             PointRef[] itemsAtArea      = d_InventoryUtil.ItemsAtArea(pos.AreaX, pos.AreaY,
                                                                       d_Items.ItemSizeX(d_Inventory.DragDropItem), d_Items.ItemSizeY(d_Inventory.DragDropItem), itemsAtAreaCount);
             if (itemsAtArea == null || itemsAtAreaCount.value > 1)
             {
                 //invalid area
                 return;
             }
             if (itemsAtAreaCount.value == 0)
             {
                 d_Inventory.Items.Add(new ProtoPoint(pos.AreaX, pos.AreaY), d_Inventory.DragDropItem);
                 d_Inventory.DragDropItem = null;
             }
             else //1
             {
                 var swapWith = itemsAtArea[0];
                 //try to stack
                 Item stackResult = d_Items.Stack(d_Inventory.Items[new ProtoPoint(swapWith.X, swapWith.Y)], d_Inventory.DragDropItem);
                 if (stackResult != null)
                 {
                     d_Inventory.Items[new ProtoPoint(swapWith.X, swapWith.Y)] = stackResult;
                     d_Inventory.DragDropItem = null;
                 }
                 else
                 {
                     //try to swap
                     //swap (swapWith, dragdropitem)
                     Item z = d_Inventory.Items[new ProtoPoint(swapWith.X, swapWith.Y)];
                     d_Inventory.Items.Remove(new ProtoPoint(swapWith.X, swapWith.Y));
                     d_Inventory.Items[new ProtoPoint(pos.AreaX, pos.AreaY)] = d_Inventory.DragDropItem;
                     d_Inventory.DragDropItem = z;
                 }
             }
             SendInventory();
         }
     }
     else if (pos.Type == Packet_InventoryPositionTypeEnum.Ground)
     {
         /*
          * if (d_Inventory.DragDropItem != null)
          * {
          *  d_DropItem.DropItem(ref d_Inventory.DragDropItem,
          *      new Vector3i(pos.GroundPositionX, pos.GroundPositionY, pos.GroundPositionZ));
          *  SendInventory();
          * }
          */
     }
     else if (pos.Type == Packet_InventoryPositionTypeEnum.MaterialSelector)
     {
         if (d_Inventory.DragDropItem == null && d_Inventory.RightHand[pos.MaterialId] != null)
         {
             d_Inventory.DragDropItem = d_Inventory.RightHand[pos.MaterialId];
             d_Inventory.RightHand[pos.MaterialId] = null;
         }
         else if (d_Inventory.DragDropItem != null && d_Inventory.RightHand[pos.MaterialId] == null)
         {
             if (d_Items.CanWear(WearPlace_.RightHand, d_Inventory.DragDropItem))
             {
                 d_Inventory.RightHand[pos.MaterialId] = d_Inventory.DragDropItem;
                 d_Inventory.DragDropItem = null;
             }
         }
         else if (d_Inventory.DragDropItem != null && d_Inventory.RightHand[pos.MaterialId] != null)
         {
             if (d_Items.CanWear(WearPlace_.RightHand, d_Inventory.DragDropItem))
             {
                 Item oldHand = d_Inventory.RightHand[pos.MaterialId];
                 d_Inventory.RightHand[pos.MaterialId] = d_Inventory.DragDropItem;
                 d_Inventory.DragDropItem = oldHand;
             }
         }
         SendInventory();
     }
     else if (pos.Type == Packet_InventoryPositionTypeEnum.WearPlace)
     {
         //just swap.
         Item wear = d_InventoryUtil.ItemAtWearPlace(pos.WearPlace, pos.ActiveMaterial);
         if (d_Items.CanWear(pos.WearPlace, d_Inventory.DragDropItem))
         {
             d_InventoryUtil.SetItemAtWearPlace(pos.WearPlace, pos.ActiveMaterial, d_Inventory.DragDropItem);
             d_Inventory.DragDropItem = wear;
         }
         SendInventory();
     }
     else
     {
         throw new Exception();
     }
 }
示例#21
0
    public bool GrabItem(Item item, int ActiveMaterial)
    {
        switch (item.ItemClass)
        {
        case ItemClass.Block:
            if (item.BlockId == SpecialBlockId.Empty)
            {
                return(true);
            }
            //stacking
            for (int i = 0; i < 10; i++)
            {
                if (d_Inventory.RightHand[i] == null)
                {
                    continue;
                }
                Item result = d_Items.Stack(d_Inventory.RightHand[i], item);
                if (result != null)
                {
                    d_Inventory.RightHand[i] = result;
                    return(true);
                }
            }
            if (d_Inventory.RightHand[ActiveMaterial] == null)
            {
                d_Inventory.RightHand[ActiveMaterial] = item;
                return(true);
            }
            //current hand
            if (d_Inventory.RightHand[ActiveMaterial].ItemClass == ItemClass.Block &&
                d_Inventory.RightHand[ActiveMaterial].BlockId == item.BlockId)
            {
                d_Inventory.RightHand[ActiveMaterial].BlockCount++;
                return(true);
            }
            //any free hand
            for (int i = 0; i < 10; i++)
            {
                if (d_Inventory.RightHand[i] == null)
                {
                    d_Inventory.RightHand[i] = item;
                    return(true);
                }
            }
            //grab to main area - stacking
            for (int y = 0; y < CellCountY; y++)
            {
                for (int x = 0; x < CellCountX; x++)
                {
                    IntRef     pCount = new IntRef();
                    PointRef[] p      = ItemsAtArea(x, y, d_Items.ItemSizeX(item), d_Items.ItemSizeY(item), pCount);
                    if (p != null && pCount.value == 1)
                    {
                        var stacked = d_Items.Stack(d_Inventory.Items[new ProtoPoint(p[0].X, p[0].Y)], item);
                        if (stacked != null)
                        {
                            d_Inventory.Items[new ProtoPoint(x, y)] = stacked;
                            return(true);
                        }
                    }
                }
            }
            //grab to main area - adding
            for (int y = 0; y < CellCountY; y++)
            {
                for (int x = 0; x < CellCountX; x++)
                {
                    IntRef     pCount = new IntRef();
                    PointRef[] p      = ItemsAtArea(x, y, d_Items.ItemSizeX(item), d_Items.ItemSizeY(item), pCount);
                    if (p != null && pCount.value == 0)
                    {
                        d_Inventory.Items[new ProtoPoint(x, y)] = item;
                        return(true);
                    }
                }
            }
            return(false);

        default:
            throw new NotImplementedException();
        }
    }
示例#22
0
    public override void OnNewFrameDraw3d(Game game, float deltaTime)
    {
        for (int i = 0; i < game.entitiesCount; i++)
        {
            Entity e = game.entities[i];
            if (e == null)
            {
                continue;
            }
            if (e.drawText == null)
            {
                continue;
            }
            if (e.networkPosition != null && (!e.networkPosition.PositionLoaded))
            {
                continue;
            }
            int            kKey = i;
            EntityDrawText p    = game.entities[i].drawText;
            float          posX = -game.platform.MathSin(e.position.roty) * p.dx + e.position.x;
            float          posY = p.dy + e.position.y;
            float          posZ = game.platform.MathCos(e.position.roty) * p.dz + e.position.z;
            //todo if picking
            if ((game.Dist(game.player.position.x, game.player.position.y, game.player.position.z, posX, posY, posZ) < 20) ||
                game.keyboardState[Game.KeyAltLeft] || game.keyboardState[Game.KeyAltRight])
            {
                string text = p.text;
                {
                    float shadow = (game.one * game.GetLight(game.platform.FloatToInt(posX), game.platform.FloatToInt(posZ), game.platform.FloatToInt(posY))) / Game.maxlight;

                    game.GLPushMatrix();
                    game.GLTranslate(posX, posY, posZ);

                    game.GLRotate(180, 1, 0, 0);
                    game.GLRotate(e.position.roty * 360 / (2 * Game.GetPi()), 0, 1, 0);
                    float scale = game.one * 5 / 1000;
                    game.GLScale(scale, scale, scale);

                    FontCi font = new FontCi();
                    font.family = "Arial";
                    font.size   = 14;
                    game.Draw2dText(text, font, -game.TextSizeWidth(text, 14) / 2, 0, IntRef.Create(Game.ColorFromArgb(255, 255, 255, 255)), true);

                    game.GLPopMatrix();
                }
            }
        }
    }
示例#23
0
 public abstract string[] FileReadAllLines(string path, IntRef length);
示例#24
0
    /// <summary>
    /// Creates a bitmap from a given string
    /// </summary>
    /// <param name="t">The <see cref="Text_"/> object to create an image from</param>
    /// <returns>A <see cref="BitmapCi"/> containing the rendered text</returns>
    internal BitmapCi CreateTextTexture(Text_ t)
    {
        IntRef partsCount = new IntRef();

        TextPart[] parts = DecodeColors(t.text, t.color, partsCount);

        float totalwidth  = 0;
        float totalheight = 0;

        int[] sizesX = new int[partsCount.value];
        int[] sizesY = new int[partsCount.value];

        for (int i = 0; i < partsCount.value; i++)
        {
            IntRef outWidth  = new IntRef();
            IntRef outHeight = new IntRef();
            platform.TextSize(parts[i].text, t.font, outWidth, outHeight);

            sizesX[i] = outWidth.value;
            sizesY[i] = outHeight.value;

            totalwidth += outWidth.value;
            totalheight = MathCi.MaxFloat(totalheight, outHeight.value);
        }

        int      size2X = NextPowerOfTwo(platform.FloatToInt(totalwidth) + 1);
        int      size2Y = NextPowerOfTwo(platform.FloatToInt(totalheight) + 1);
        BitmapCi bmp2   = platform.BitmapCreate(size2X, size2Y);

        int[] bmp2Pixels = new int[size2X * size2Y];

        float currentwidth = 0;

        for (int i = 0; i < partsCount.value; i++)
        {
            int sizeiX = sizesX[i];
            int sizeiY = sizesY[i];
            if (sizeiX == 0 || sizeiY == 0)
            {
                continue;
            }

            Text_ partText = new Text_();
            partText.text  = parts[i].text;
            partText.color = parts[i].color;
            partText.font  = t.font;

            BitmapCi partBmp       = platform.CreateTextTexture(partText);
            int      partWidth     = platform.FloatToInt(platform.BitmapGetWidth(partBmp));
            int      partHeight    = platform.FloatToInt(platform.BitmapGetHeight(partBmp));
            int[]    partBmpPixels = new int[partWidth * partHeight];
            platform.BitmapGetPixelsArgb(partBmp, partBmpPixels);
            for (int x = 0; x < partWidth; x++)
            {
                for (int y = 0; y < partHeight; y++)
                {
                    if (x + currentwidth >= size2X)
                    {
                        continue;
                    }
                    if (y >= size2Y)
                    {
                        continue;
                    }
                    int c = partBmpPixels[MapUtilCi.Index2d(x, y, partWidth)];
                    if (Game.ColorA(c) > 0)
                    {
                        bmp2Pixels[MapUtilCi.Index2d(platform.FloatToInt(currentwidth) + x, y, size2X)] = c;
                    }
                }
            }
            currentwidth += sizeiX;
        }
        platform.BitmapSetPixelsArgb(bmp2, bmp2Pixels);
        return(bmp2);
    }
示例#25
0
 public abstract byte[] GzipCompress(byte[] data, int dataLength, IntRef retLength);
示例#26
0
    public override void Render(float dt)
    {
        GamePlatform p = menu.p;

        float scale = menu.GetScale();

        menu.DrawBackground();
        menu.DrawText(title, 20 * scale, p.GetCanvasWidth() / 2, 10, TextAlign.Center, TextBaseline.Top);

        float leftx = p.GetCanvasWidth() / 2 - 128 * scale;
        float y     = p.GetCanvasHeight() / 2 + 0 * scale;

        play.x        = leftx;
        play.y        = y + 100 * scale;
        play.sizex    = 256 * scale;
        play.sizey    = 64 * scale;
        play.fontSize = 14 * scale;

        newWorld.x        = leftx;
        newWorld.y        = y + 170 * scale;
        newWorld.sizex    = 256 * scale;
        newWorld.sizey    = 64 * scale;
        newWorld.fontSize = 14 * scale;

        modify.x        = leftx;
        modify.y        = y + 240 * scale;
        modify.sizex    = 256 * scale;
        modify.sizey    = 64 * scale;
        modify.fontSize = 14 * scale;

        back.x        = 40 * scale;
        back.y        = p.GetCanvasHeight() - 104 * scale;
        back.sizex    = 256 * scale;
        back.sizey    = 64 * scale;
        back.fontSize = 14 * scale;

        open.x        = leftx;
        open.y        = y + 0 * scale;
        open.sizex    = 256 * scale;
        open.sizey    = 64 * scale;
        open.fontSize = 14 * scale;

        if (savegames == null)
        {
            IntRef savegamesCount_ = new IntRef();
            savegames      = menu.GetSavegames(savegamesCount_);
            savegamesCount = savegamesCount_.value;
        }

        for (int i = 0; i < 10; i++)
        {
            worldButtons[i].visible = false;
        }
        for (int i = 0; i < savegamesCount; i++)
        {
            worldButtons[i].visible  = true;
            worldButtons[i].text     = menu.p.FileName(savegames[i]);
            worldButtons[i].x        = leftx;
            worldButtons[i].y        = 100 + 100 * scale * i;
            worldButtons[i].sizex    = 256 * scale;
            worldButtons[i].sizey    = 64 * scale;
            worldButtons[i].fontSize = 14 * scale;
        }

        open.visible     = menu.p.SinglePlayerServerAvailable();
        play.visible     = false;
        newWorld.visible = false;
        modify.visible   = false;
        for (int i = 0; i < savegamesCount; i++)
        {
            worldButtons[i].visible = false;
        }

        DrawWidgets();

        if (!menu.p.SinglePlayerServerAvailable())
        {
            menu.DrawText("Singleplayer is only available on desktop (Windows, Linux, Mac) version of game.", 16 * scale, menu.p.GetCanvasWidth() / 2, menu.p.GetCanvasHeight() / 2, TextAlign.Center, TextBaseline.Middle);
        }
    }
示例#27
0
 public abstract byte[] StringToUtf8ByteArray(string s, IntRef retLength);
示例#28
0
    public override void Render(float dt)
    {
        if (!loaded)
        {
            menu.p.WebClientDownloadDataAsync("http://manicdigger.sourceforge.net/serverlistcsv.php", serverListAddress);
            loaded = true;
        }
        if (serverListAddress.done)
        {
            serverListAddress.done = false;
            menu.p.WebClientDownloadDataAsync(serverListAddress.GetString(menu.p), serverListCsv);
        }
        if (serverListCsv.done)
        {
            loading            = false;
            serverListCsv.done = false;
            for (int i = 0; i < serversOnListCount; i++)
            {
                serversOnList[i]  = null;
                thumbResponses[i] = null;
            }
            IntRef   serversCount = new IntRef();
            string[] servers      = menu.p.StringSplit(serverListCsv.GetString(menu.p), "\n", serversCount);
            for (int i = 0; i < serversCount.value; i++)
            {
                IntRef   ssCount = new IntRef();
                string[] ss      = menu.p.StringSplit(servers[i], "\t", ssCount);
                if (ssCount.value < 10)
                {
                    continue;
                }
                ServerOnList s = new ServerOnList();
                s.hash           = ss[0];
                s.name           = menu.p.DecodeHTMLEntities(ss[1]);
                s.motd           = menu.p.DecodeHTMLEntities(ss[2]);
                s.port           = menu.p.IntParse(ss[3]);
                s.ip             = ss[4];
                s.version        = ss[5];
                s.users          = menu.p.IntParse(ss[6]);
                s.max            = menu.p.IntParse(ss[7]);
                s.gamemode       = ss[8];
                s.players        = ss[9];
                serversOnList[i] = s;
            }
        }

        GamePlatform p = menu.p;

        float scale = menu.GetScale();

        back.x        = 40 * scale;
        back.y        = p.GetCanvasHeight() - 104 * scale;
        back.sizex    = 256 * scale;
        back.sizey    = 64 * scale;
        back.fontSize = 14 * scale;

        connect.x        = p.GetCanvasWidth() / 2 - 300 * scale;
        connect.y        = p.GetCanvasHeight() - 104 * scale;
        connect.sizex    = 256 * scale;
        connect.sizey    = 64 * scale;
        connect.fontSize = 14 * scale;

        connectToIp.x        = p.GetCanvasWidth() / 2 - 0 * scale;
        connectToIp.y        = p.GetCanvasHeight() - 104 * scale;
        connectToIp.sizex    = 256 * scale;
        connectToIp.sizey    = 64 * scale;
        connectToIp.fontSize = 14 * scale;

        refresh.x        = p.GetCanvasWidth() / 2 + 350 * scale;
        refresh.y        = p.GetCanvasHeight() - 104 * scale;
        refresh.sizex    = 256 * scale;
        refresh.sizey    = 64 * scale;
        refresh.fontSize = 14 * scale;

        pageUp.x     = p.GetCanvasWidth() - 94 * scale;
        pageUp.y     = 100 * scale + (serversPerPage - 1) * 70 * scale;
        pageUp.sizex = 64 * scale;
        pageUp.sizey = 64 * scale;
        pageUp.image = "serverlist_nav_down.png";

        pageDown.x     = p.GetCanvasWidth() - 94 * scale;
        pageDown.y     = 100 * scale;
        pageDown.sizex = 64 * scale;
        pageDown.sizey = 64 * scale;
        pageDown.image = "serverlist_nav_up.png";

        loggedInName.x        = p.GetCanvasWidth() - 228 * scale;
        loggedInName.y        = 32 * scale;
        loggedInName.sizex    = 128 * scale;
        loggedInName.sizey    = 32 * scale;
        loggedInName.fontSize = 12 * scale;
        if (loggedInName.text == "")
        {
            if (p.GetPreferences().GetString("Password", "") != "")
            {
                loggedInName.text = p.GetPreferences().GetString("Username", "Invalid");
            }
        }
        logout.visible = loggedInName.text != "";

        logout.x        = p.GetCanvasWidth() - 228 * scale;
        logout.y        = 62 * scale;
        logout.sizex    = 128 * scale;
        logout.sizey    = 32 * scale;
        logout.fontSize = 12 * scale;
        logout.text     = "Logout";

        menu.DrawBackground();
        menu.DrawText(title, 20 * scale, p.GetCanvasWidth() / 2, 10, TextAlign.Center, TextBaseline.Top);
        menu.DrawText(p.IntToString(page + 1), 14 * scale, p.GetCanvasWidth() - 68 * scale, p.GetCanvasHeight() / 2, TextAlign.Center, TextBaseline.Middle);

        if (loading)
        {
            menu.DrawText(menu.lang.Get("MainMenu_MultiplayerLoading"), 14 * scale, 100 * scale, 50 * scale, TextAlign.Left, TextBaseline.Top);
        }

        UpdateThumbnails();
        for (int i = 0; i < serverButtonsCount; i++)
        {
            serverButtons[i].visible = false;
        }

        serversPerPage = menu.p.FloatToInt((menu.p.GetCanvasHeight() - (2 * 100 * scale)) / 70 * scale);
        for (int i = 0; i < serversPerPage; i++)
        {
            int index = i + (serversPerPage * page);
            if (index > serversOnListCount)
            {
                //Reset to first page
                page  = 0;
                index = i + (serversPerPage * page);
            }
            ServerOnList s = serversOnList[index];
            if (s == null)
            {
                continue;
            }
            string t = menu.p.StringFormat2("{1}", menu.p.IntToString(index), s.name);
            t = menu.p.StringFormat2("{0}\n{1}", t, s.motd);
            t = menu.p.StringFormat2("{0}\n{1}", t, s.gamemode);
            t = menu.p.StringFormat2("{0}\n{1}", t, menu.p.IntToString(s.users));
            t = menu.p.StringFormat2("{0}/{1}", t, menu.p.IntToString(s.max));
            t = menu.p.StringFormat2("{0}\n{1}", t, s.version);

            serverButtons[i].text        = t;
            serverButtons[i].x           = 100 * scale;
            serverButtons[i].y           = 100 * scale + i * 70 * scale;
            serverButtons[i].sizex       = p.GetCanvasWidth() - 200 * scale;
            serverButtons[i].sizey       = 64 * scale;
            serverButtons[i].visible     = true;
            serverButtons[i].buttonStyle = ButtonStyle.ServerEntry;
            if (s.thumbnailError)
            {
                //Server did not respond to ServerQuery. Maybe not reachable?
                serverButtons[i].description = "Server did not respond to query!";
            }
            else
            {
                serverButtons[i].description = null;
            }
            if (s.thumbnailFetched && !s.thumbnailError)
            {
                serverButtons[i].image = menu.p.StringFormat("serverlist_entry_{0}.png", s.hash);
            }
            else
            {
                serverButtons[i].image = "serverlist_entry_noimage.png";
            }
        }
        UpdateScrollButtons();
        DrawWidgets();
    }
示例#29
0
    public static string StringAppend(GamePlatform p, string a, string b)
    {
        IntRef aLength = new IntRef();
        int[] aChars = p.StringToCharArray(a, aLength);
        IntRef bLength = new IntRef();
        int[] bChars = p.StringToCharArray(b, bLength);

        int[] cChars = new int[aLength.value + bLength.value];
        for (int i = 0; i < aLength.value; i++)
        {
            cChars[i] = aChars[i];
        }
        for (int i = 0; i < bLength.value; i++)
        {
            cChars[i + aLength.value] = bChars[i];
        }
        return p.CharArrayToString(cChars, aLength.value + bLength.value);
    }
    internal void ProcessPacket(Packet_Server packet)
    {
        if (game.packetHandlers[packet.Id] != null)
        {
            game.packetHandlers[packet.Id].Handle(game, packet);
        }
        switch (packet.Id)
        {
        case Packet_ServerIdEnum.ServerIdentification:
        {
            string invalidversionstr = game.language.InvalidVersionConnectAnyway();

            game.serverGameVersion = packet.Identification.MdProtocolVersion;
            if (game.serverGameVersion != game.platform.GetGameVersion())
            {
                game.ChatLog("[GAME] Different game versions");
                string q = game.platform.StringFormat2(invalidversionstr, game.platform.GetGameVersion(), game.serverGameVersion);
                game.invalidVersionDrawMessage          = q;
                game.invalidVersionPacketIdentification = packet;
            }
            else
            {
                game.ProcessServerIdentification(packet);
            }
            game.ReceivedMapLength = 0;
        }
        break;

        case Packet_ServerIdEnum.Ping:
        {
            game.SendPingReply();
            game.ServerInfo.ServerPing.Send(game.platform.TimeMillisecondsFromStart());
        }
        break;

        case Packet_ServerIdEnum.PlayerPing:
        {
            game.ServerInfo.ServerPing.Receive(game.platform.TimeMillisecondsFromStart());
            game.performanceinfo.Set("Ping", game.platform.IntToString(game.ServerInfo.ServerPing.RoundtripTimeTotalMilliseconds()));
        }
        break;

        case Packet_ServerIdEnum.LevelInitialize:
        {
            game.ChatLog("[GAME] Initialized map loading");
            game.ReceivedMapLength = 0;
            game.InvokeMapLoadingProgress(0, 0, game.language.Connecting());
        }
        break;

        case Packet_ServerIdEnum.LevelDataChunk:
        {
            game.InvokeMapLoadingProgress(packet.LevelDataChunk.PercentComplete, game.ReceivedMapLength, packet.LevelDataChunk.Status);
        }
        break;

        case Packet_ServerIdEnum.LevelFinalize:
        {
            game.ChatLog("[GAME] Finished map loading");
        }
        break;

        case Packet_ServerIdEnum.SetBlock:
        {
            int x    = packet.SetBlock.X;
            int y    = packet.SetBlock.Y;
            int z    = packet.SetBlock.Z;
            int type = packet.SetBlock.BlockType;
            //try
            {
                game.SetTileAndUpdate(x, y, z, type);
            }
            //catch { Console.WriteLine("Cannot update tile!"); }
        }
        break;

        case Packet_ServerIdEnum.FillArea:
        {
            int ax = packet.FillArea.X1;
            int ay = packet.FillArea.Y1;
            int az = packet.FillArea.Z1;
            int bx = packet.FillArea.X2;
            int by = packet.FillArea.Y2;
            int bz = packet.FillArea.Z2;

            int startx = MathCi.MinInt(ax, bx);
            int endx   = MathCi.MaxInt(ax, bx);
            int starty = MathCi.MinInt(ay, by);
            int endy   = MathCi.MaxInt(ay, by);
            int startz = MathCi.MinInt(az, bz);
            int endz   = MathCi.MaxInt(az, bz);

            int blockCount = packet.FillArea.BlockCount;
            {
                for (int x = startx; x <= endx; x++)
                {
                    for (int y = starty; y <= endy; y++)
                    {
                        for (int z = startz; z <= endz; z++)
                        {
                            // if creative mode is off and player run out of blocks
                            if (blockCount == 0)
                            {
                                return;
                            }
                            //try
                            {
                                game.SetTileAndUpdate(x, y, z, packet.FillArea.BlockType);
                            }
                            //catch
                            //{
                            //    Console.WriteLine("Cannot update tile!");
                            //}
                            blockCount--;
                        }
                    }
                }
            }
        }
        break;

        case Packet_ServerIdEnum.FillAreaLimit:
        {
            game.fillAreaLimit = packet.FillAreaLimit.Limit;
            if (game.fillAreaLimit > 100000)
            {
                game.fillAreaLimit = 100000;
            }
        }
        break;

        case Packet_ServerIdEnum.Freemove:
        {
            game.AllowFreemove = packet.Freemove.IsEnabled != 0;
            if (!game.AllowFreemove)
            {
                game.controls.SetFreemove(FreemoveLevelEnum.None);
                game.movespeed = game.basemovespeed;
                game.Log(game.language.MoveNormal());
            }
        }
        break;

        case Packet_ServerIdEnum.PlayerSpawnPosition:
        {
            int x = packet.PlayerSpawnPosition.X;
            int y = packet.PlayerSpawnPosition.Y;
            int z = packet.PlayerSpawnPosition.Z;
            game.playerPositionSpawnX = x;
            game.playerPositionSpawnY = z;
            game.playerPositionSpawnZ = y;
            game.Log(game.platform.StringFormat(game.language.SpawnPositionSetTo(), game.platform.StringFormat3("{0},{1},{2}", game.platform.IntToString(x), game.platform.IntToString(y), game.platform.IntToString(z))));
        }
        break;

        case Packet_ServerIdEnum.Message:
        {
            game.AddChatline(packet.Message.Message);
            game.ChatLog(packet.Message.Message);
        }
        break;

        case Packet_ServerIdEnum.DisconnectPlayer:
        {
            game.ChatLog(game.platform.StringFormat("[GAME] Disconnected by the server ({0})", packet.DisconnectPlayer.DisconnectReason));
            //Exit mouse pointer lock if necessary
            if (game.platform.IsMousePointerLocked())
            {
                game.platform.ExitMousePointerLock();
            }
            //When server disconnects player, return to main menu
            game.platform.MessageBoxShowError(packet.DisconnectPlayer.DisconnectReason, "Disconnected from server");
            game.ExitToMainMenu_();
            break;
        }

        case Packet_ServerIdEnum.PlayerStats:
        {
            Packet_ServerPlayerStats p = packet.PlayerStats;
            game.PlayerStats = p;
        }
        break;

        case Packet_ServerIdEnum.FiniteInventory:
        {
            //check for null so it's possible to connect
            //to old versions of game (before 2011-05-05)
            if (packet.Inventory.Inventory != null)
            {
                //d_Inventory.CopyFrom(ConvertInventory(packet.Inventory.Inventory));
                game.UseInventory(packet.Inventory.Inventory);
            }
            //FiniteInventory = packet.FiniteInventory.BlockTypeAmount;
            //ENABLE_FINITEINVENTORY = packet.FiniteInventory.IsFinite;
            //FiniteInventoryMax = packet.FiniteInventory.Max;
        }
        break;

        case Packet_ServerIdEnum.Season:
        {
            packet.Season.Hour -= 1;
            if (packet.Season.Hour < 0)
            {
                //shouldn't happen
                packet.Season.Hour = 12 * Game.HourDetail;
            }
            int sunlight = game.NightLevels[packet.Season.Hour];
            game.SkySphereNight = sunlight < 8;
            game.d_SunMoonRenderer.day_length_in_seconds = 60 * 60 * 24 / packet.Season.DayNightCycleSpeedup;
            int hour = packet.Season.Hour / Game.HourDetail;
            if (game.d_SunMoonRenderer.GetHour() != hour)
            {
                game.d_SunMoonRenderer.SetHour(hour);
            }

            if (game.sunlight_ != sunlight)
            {
                game.sunlight_ = sunlight;
                //d_Shadows.ResetShadows();
                game.RedrawAllBlocks();
            }
        }
        break;

        case Packet_ServerIdEnum.BlobInitialize:
        {
            game.blobdownload = new CitoMemoryStream();
            //blobdownloadhash = ByteArrayToString(packet.BlobInitialize.hash);
            game.blobdownloadname = packet.BlobInitialize.Name;
            game.blobdownloadmd5  = packet.BlobInitialize.Md5;
        }
        break;

        case Packet_ServerIdEnum.BlobPart:
        {
            int length = game.platform.ByteArrayLength(packet.BlobPart.Data);
            game.blobdownload.Write(packet.BlobPart.Data, 0, length);
            game.ReceivedMapLength += length;
        }
        break;

        case Packet_ServerIdEnum.BlobFinalize:
        {
            byte[] downloaded = game.blobdownload.ToArray();

            if (game.blobdownloadname != null)         // old servers
            {
                game.SetFile(game.blobdownloadname, game.blobdownloadmd5, downloaded, game.blobdownload.Length());
            }
            game.blobdownload = null;
        }
        break;

        case Packet_ServerIdEnum.Sound:
        {
            game.PlaySoundAt(packet.Sound.Name, packet.Sound.X, packet.Sound.Y, packet.Sound.Z);
        }
        break;

        case Packet_ServerIdEnum.RemoveMonsters:
        {
            for (int i = Game.entityMonsterIdStart; i < Game.entityMonsterIdStart + Game.entityMonsterIdCount; i++)
            {
                game.entities[i] = null;
            }
        }
        break;

        case Packet_ServerIdEnum.Translation:
            game.language.Override(packet.Translation.Lang, packet.Translation.Id, packet.Translation.Translation);
            break;

        case Packet_ServerIdEnum.BlockType:
            game.NewBlockTypes[packet.BlockType.Id] = packet.BlockType.Blocktype;
            break;

        case Packet_ServerIdEnum.SunLevels:
            game.NightLevels = packet.SunLevels.Sunlevels;
            break;

        case Packet_ServerIdEnum.LightLevels:
            for (int i = 0; i < packet.LightLevels.LightlevelsCount; i++)
            {
                game.mLightLevels[i] = game.DeserializeFloat(packet.LightLevels.Lightlevels[i]);
            }
            break;

        case Packet_ServerIdEnum.Follow:
            IntRef oldFollowId = game.FollowId();
            game.Follow = packet.Follow.Client;
            if (packet.Follow.Tpp != 0)
            {
                game.SetCamera(CameraType.Overhead);
                game.player.position.rotx = Game.GetPi();
                game.GuiStateBackToGame();
            }
            else
            {
                game.SetCamera(CameraType.Fpp);
            }
            break;

        case Packet_ServerIdEnum.Bullet:
            game.EntityAddLocal(game.CreateBulletEntity(
                                    game.DeserializeFloat(packet.Bullet.FromXFloat),
                                    game.DeserializeFloat(packet.Bullet.FromYFloat),
                                    game.DeserializeFloat(packet.Bullet.FromZFloat),
                                    game.DeserializeFloat(packet.Bullet.ToXFloat),
                                    game.DeserializeFloat(packet.Bullet.ToYFloat),
                                    game.DeserializeFloat(packet.Bullet.ToZFloat),
                                    game.DeserializeFloat(packet.Bullet.SpeedFloat)));
            break;

        case Packet_ServerIdEnum.Ammo:
            if (!game.ammostarted)
            {
                game.ammostarted = true;
                for (int i = 0; i < packet.Ammo.TotalAmmoCount; i++)
                {
                    Packet_IntInt k = packet.Ammo.TotalAmmo[i];
                    game.LoadedAmmo[k.Key_] = MathCi.MinInt(k.Value_, game.blocktypes[k.Key_].AmmoMagazine);
                }
            }
            game.TotalAmmo = new int[GlobalVar.MAX_BLOCKTYPES];
            for (int i = 0; i < packet.Ammo.TotalAmmoCount; i++)
            {
                game.TotalAmmo[packet.Ammo.TotalAmmo[i].Key_] = packet.Ammo.TotalAmmo[i].Value_;
            }
            break;

        case Packet_ServerIdEnum.Explosion:
        {
            Entity entity = new Entity();
            entity.expires          = new Expires();
            entity.expires.timeLeft = game.DeserializeFloat(packet.Explosion.TimeFloat);
            entity.push             = packet.Explosion;
            game.EntityAddLocal(entity);
        }
        break;

        case Packet_ServerIdEnum.Projectile:
        {
            Entity entity = new Entity();

            Sprite sprite = new Sprite();
            sprite.image          = "ChemicalGreen.png";
            sprite.size           = 14;
            sprite.animationcount = 0;
            sprite.positionX      = game.DeserializeFloat(packet.Projectile.FromXFloat);
            sprite.positionY      = game.DeserializeFloat(packet.Projectile.FromYFloat);
            sprite.positionZ      = game.DeserializeFloat(packet.Projectile.FromZFloat);
            entity.sprite         = sprite;

            Grenade_ grenade = new Grenade_();
            grenade.velocityX    = game.DeserializeFloat(packet.Projectile.VelocityXFloat);
            grenade.velocityY    = game.DeserializeFloat(packet.Projectile.VelocityYFloat);
            grenade.velocityZ    = game.DeserializeFloat(packet.Projectile.VelocityZFloat);
            grenade.block        = packet.Projectile.BlockId;
            grenade.sourcePlayer = packet.Projectile.SourcePlayerID;
            entity.grenade       = grenade;

            entity.expires = Expires.Create(game.DeserializeFloat(packet.Projectile.ExplodesAfterFloat));

            game.EntityAddLocal(entity);
        }
        break;

        case Packet_ServerIdEnum.BlockTypes:
            game.blocktypes    = game.NewBlockTypes;
            game.NewBlockTypes = new Packet_BlockType[GlobalVar.MAX_BLOCKTYPES];

            int      textureInAtlasIdsCount = 1024;
            string[] textureInAtlasIds      = new string[textureInAtlasIdsCount];
            int      lastTextureId          = 0;
            for (int i = 0; i < GlobalVar.MAX_BLOCKTYPES; i++)
            {
                if (game.blocktypes[i] != null)
                {
                    string[] to_load       = new string[7];
                    int      to_loadLength = 7;
                    {
                        to_load[0] = game.blocktypes[i].TextureIdLeft;
                        to_load[1] = game.blocktypes[i].TextureIdRight;
                        to_load[2] = game.blocktypes[i].TextureIdFront;
                        to_load[3] = game.blocktypes[i].TextureIdBack;
                        to_load[4] = game.blocktypes[i].TextureIdTop;
                        to_load[5] = game.blocktypes[i].TextureIdBottom;
                        to_load[6] = game.blocktypes[i].TextureIdForInventory;
                    }
                    for (int k = 0; k < to_loadLength; k++)
                    {
                        if (!Contains(textureInAtlasIds, textureInAtlasIdsCount, to_load[k]))
                        {
                            textureInAtlasIds[lastTextureId++] = to_load[k];
                        }
                    }
                }
            }
            game.d_Data.UseBlockTypes(game.blocktypes, GlobalVar.MAX_BLOCKTYPES);
            for (int i = 0; i < GlobalVar.MAX_BLOCKTYPES; i++)
            {
                Packet_BlockType b = game.blocktypes[i];
                if (b == null)
                {
                    continue;
                }
                //Indexed by block id and TileSide.
                if (textureInAtlasIds != null)
                {
                    game.TextureId[i][0]          = IndexOf(textureInAtlasIds, textureInAtlasIdsCount, b.TextureIdTop);
                    game.TextureId[i][1]          = IndexOf(textureInAtlasIds, textureInAtlasIdsCount, b.TextureIdBottom);
                    game.TextureId[i][2]          = IndexOf(textureInAtlasIds, textureInAtlasIdsCount, b.TextureIdFront);
                    game.TextureId[i][3]          = IndexOf(textureInAtlasIds, textureInAtlasIdsCount, b.TextureIdBack);
                    game.TextureId[i][4]          = IndexOf(textureInAtlasIds, textureInAtlasIdsCount, b.TextureIdLeft);
                    game.TextureId[i][5]          = IndexOf(textureInAtlasIds, textureInAtlasIdsCount, b.TextureIdRight);
                    game.TextureIdForInventory[i] = IndexOf(textureInAtlasIds, textureInAtlasIdsCount, b.TextureIdForInventory);
                }
            }
            game.UseTerrainTextures(textureInAtlasIds, textureInAtlasIdsCount);
            game.handRedraw = true;
            game.RedrawAllBlocks();
            break;

        case Packet_ServerIdEnum.ServerRedirect:
            game.ChatLog("[GAME] Received server redirect");
            //Leave current server
            game.SendLeave(Packet_LeaveReasonEnum.Leave);
            //Exit game screen and create new game instance
            game.ExitAndSwitchServer(packet.Redirect);
            break;
        }
    }
示例#31
0
    public override void Render(float dt)
    {
        GamePlatform p = menu.p;

        float scale = menu.GetScale();

        menu.DrawBackground();
        menu.DrawText(title, 20 * scale, p.GetCanvasWidth() / 2, 10, TextAlign.Center, TextBaseline.Top);

        float leftx = p.GetCanvasWidth() / 2 - 128 * scale;
        float y = p.GetCanvasHeight() / 2 + 0 * scale;

        play.x = leftx;
        play.y = y + 100 * scale;
        play.sizex = 256 * scale;
        play.sizey = 64 * scale;
        play.fontSize = 14 * scale;

        newWorld.x = leftx;
        newWorld.y = y + 170 * scale;
        newWorld.sizex = 256 * scale;
        newWorld.sizey = 64 * scale;
        newWorld.fontSize = 14 * scale;

        modify.x = leftx;
        modify.y = y + 240 * scale;
        modify.sizex = 256 * scale;
        modify.sizey = 64 * scale;
        modify.fontSize = 14 * scale;

        back.x = 40 * scale;
        back.y = p.GetCanvasHeight() - 104 * scale;
        back.sizex = 256 * scale;
        back.sizey = 64 * scale;
        back.fontSize = 14 * scale;

        open.x = leftx;
        open.y = y + 0 * scale;
        open.sizex = 256 * scale;
        open.sizey = 64 * scale;
        open.fontSize = 14 * scale;

        if (savegames == null)
        {
            IntRef savegamesCount_ = new IntRef();
            savegames = menu.GetSavegames(savegamesCount_);
            savegamesCount = savegamesCount_.value;
        }

        for (int i = 0; i < 10; i++)
        {
            worldButtons[i].visible = false;
        }
        for (int i = 0; i < savegamesCount; i++)
        {
            worldButtons[i].visible = true;
            worldButtons[i].text = menu.p.FileName(savegames[i]);
            worldButtons[i].x = leftx;
            worldButtons[i].y = 100 + 100 * scale * i;
            worldButtons[i].sizex = 256 * scale;
            worldButtons[i].sizey = 64 * scale;
            worldButtons[i].fontSize = 14 * scale;
        }

        open.visible = menu.p.SinglePlayerServerAvailable();
        play.visible = false;
        newWorld.visible = false;
        modify.visible = false;
        for (int i = 0; i < savegamesCount; i++)
        {
            worldButtons[i].visible = false;
        }

        DrawWidgets();

        if (!menu.p.SinglePlayerServerAvailable())
        {
            menu.DrawText("Singleplayer is only available on desktop (Windows, Linux, Mac) version of game.", 16 * scale, menu.p.GetCanvasWidth() / 2, menu.p.GetCanvasHeight() / 2, TextAlign.Center, TextBaseline.Middle);
        }
    }
示例#32
0
    public override void OnNewFrameDraw2d(Game game_, float deltaTime)
    {
        game = game_;
        if (dataItems == null)
        {
            dataItems      = new GameDataItemsClient();
            dataItems.game = game_;
            controller     = ClientInventoryController.Create(game_);
            inventoryUtil  = game.d_InventoryUtil;
        }
        if (game.guistate == GuiState.MapLoading)
        {
            return;
        }
        DrawMaterialSelector();
        if (game.guistate != GuiState.Inventory)
        {
            return;
        }
        if (ScrollingUpTimeMilliseconds != 0 && (game.platform.TimeMillisecondsFromStart() - ScrollingUpTimeMilliseconds) > 250)
        {
            ScrollingUpTimeMilliseconds = game.platform.TimeMillisecondsFromStart();
            ScrollUp();
        }
        if (ScrollingDownTimeMilliseconds != 0 && (game.platform.TimeMillisecondsFromStart() - ScrollingDownTimeMilliseconds) > 250)
        {
            ScrollingDownTimeMilliseconds = game.platform.TimeMillisecondsFromStart();
            ScrollDown();
        }

        PointRef scaledMouse = PointRef.Create(game.mouseCurrentX, game.mouseCurrentY);

        game.Draw2dBitmapFile("inventory.png", InventoryStartX(), InventoryStartY(), 1024, 1024);

        //the3d.Draw2dTexture(terrain, 50, 50, 50, 50, 0);
        //the3d.Draw2dBitmapFile("inventory_weapon_shovel.png", 100, 100, 60 * 2, 60 * 4);
        //the3d.Draw2dBitmapFile("inventory_gauntlet_gloves.png", 200, 200, 60 * 2, 60 * 2);
        //main inventory
        for (int i = 0; i < game.d_Inventory.ItemsCount; i++)
        {
            Packet_PositionItem k = game.d_Inventory.Items[i];
            if (k == null)
            {
                continue;
            }
            int screeny = k.Y - ScrollLine;
            if (screeny >= 0 && screeny < CellCountInPageY)
            {
                DrawItem(CellsStartX() + k.X * CellDrawSize, CellsStartY() + screeny * CellDrawSize, k.Value_, 0, 0);
            }
        }

        //draw area selection
        if (game.d_Inventory.DragDropItem != null)
        {
            PointRef selectedInPage = SelectedCell(scaledMouse);
            if (selectedInPage != null)
            {
                int x     = (selectedInPage.X) * CellDrawSize + CellsStartX();
                int y     = (selectedInPage.Y) * CellDrawSize + CellsStartY();
                int sizex = dataItems.ItemSizeX(game.d_Inventory.DragDropItem);
                int sizey = dataItems.ItemSizeY(game.d_Inventory.DragDropItem);
                if (selectedInPage.X + sizex <= CellCountInPageX &&
                    selectedInPage.Y + sizey <= CellCountInPageY)
                {
                    int        c;
                    IntRef     itemsAtAreaCount = new IntRef();
                    PointRef[] itemsAtArea      = inventoryUtil.ItemsAtArea(selectedInPage.X, selectedInPage.Y + ScrollLine, sizex, sizey, itemsAtAreaCount);
                    if (itemsAtArea == null || itemsAtAreaCount.value > 1)
                    {
                        c = Game.ColorFromArgb(100, 255, 0, 0); // red
                    }
                    else //0 or 1
                    {
                        c = Game.ColorFromArgb(100, 0, 255, 0); // green
                    }
                    game.Draw2dTexture(game.WhiteTexture(), x, y,
                                       CellDrawSize * sizex, CellDrawSize * sizey,
                                       null, 0, c, false);
                }
            }
            IntRef selectedWear = SelectedWearPlace(scaledMouse);
            if (selectedWear != null)
            {
                PointRef p    = PointRef.Create(wearPlaceStart[selectedWear.value].X + InventoryStartX(), wearPlaceStart[selectedWear.value].Y + InventoryStartY());
                PointRef size = wearPlaceCells[selectedWear.value];

                int         c;
                Packet_Item itemsAtArea = inventoryUtil.ItemAtWearPlace(selectedWear.value, game.ActiveMaterial);
                if (!dataItems.CanWear(selectedWear.value, game.d_Inventory.DragDropItem))
                {
                    c = Game.ColorFromArgb(100, 255, 0, 0); // red
                }
                else //0 or 1
                {
                    c = Game.ColorFromArgb(100, 0, 255, 0); // green
                }
                game.Draw2dTexture(game.WhiteTexture(), p.X, p.Y,
                                   CellDrawSize * size.X, CellDrawSize * size.Y,
                                   null, 0, c, false);
            }
        }

        //material selector
        DrawMaterialSelector();

        //wear
        //DrawItem(Offset(wearPlaceStart[(int)WearPlace.LeftHand], InventoryStart), inventory.LeftHand[ActiveMaterial.ActiveMaterial], null);
        DrawItem(wearPlaceStart[WearPlace_.RightHand].X + InventoryStartX(), wearPlaceStart[WearPlace_.RightHand].Y + InventoryStartY(), game.d_Inventory.RightHand[game.ActiveMaterial], 0, 0);
        DrawItem(wearPlaceStart[WearPlace_.MainArmor].X + InventoryStartX(), wearPlaceStart[WearPlace_.MainArmor].Y + InventoryStartY(), game.d_Inventory.MainArmor, 0, 0);
        DrawItem(wearPlaceStart[WearPlace_.Boots].X + InventoryStartX(), wearPlaceStart[WearPlace_.Boots].Y + InventoryStartY(), game.d_Inventory.Boots, 0, 0);
        DrawItem(wearPlaceStart[WearPlace_.Helmet].X + InventoryStartX(), wearPlaceStart[WearPlace_.Helmet].Y + InventoryStartY(), game.d_Inventory.Helmet, 0, 0);
        DrawItem(wearPlaceStart[WearPlace_.Gauntlet].X + InventoryStartX(), wearPlaceStart[WearPlace_.Gauntlet].Y + InventoryStartY(), game.d_Inventory.Gauntlet, 0, 0);

        //info
        if (SelectedCell(scaledMouse) != null)
        {
            PointRef selected = SelectedCell(scaledMouse);
            selected.Y += ScrollLine;
            PointRef itemAtCell = inventoryUtil.ItemAtCell(selected);
            if (itemAtCell != null)
            {
                Packet_Item item = GetItem(game.d_Inventory, itemAtCell.X, itemAtCell.Y);
                if (item != null)
                {
                    int x = (selected.X) * CellDrawSize + CellsStartX();
                    int y = (selected.Y) * CellDrawSize + CellsStartY();
                    DrawItemInfo(scaledMouse.X, scaledMouse.Y, item);
                }
            }
        }
        if (SelectedWearPlace(scaledMouse) != null)
        {
            int         selected        = SelectedWearPlace(scaledMouse).value;
            Packet_Item itemAtWearPlace = inventoryUtil.ItemAtWearPlace(selected, game.ActiveMaterial);
            if (itemAtWearPlace != null)
            {
                DrawItemInfo(scaledMouse.X, scaledMouse.Y, itemAtWearPlace);
            }
        }
        if (SelectedMaterialSelectorSlot(scaledMouse) != null)
        {
            int         selected = SelectedMaterialSelectorSlot(scaledMouse).value;
            Packet_Item item     = game.d_Inventory.RightHand[selected];
            if (item != null)
            {
                DrawItemInfo(scaledMouse.X, scaledMouse.Y, item);
            }
        }

        if (game.d_Inventory.DragDropItem != null)
        {
            DrawItem(scaledMouse.X, scaledMouse.Y, game.d_Inventory.DragDropItem, 0, 0);
        }
    }
示例#33
0
 public abstract byte[] StringToUtf8ByteArray(string s, IntRef retLength);
示例#34
0
    //tiles = 16 means 16 x 16 atlas
    public BitmapCi[] Atlas2dInto1d(GamePlatform p, BitmapCi atlas2d_, int tiles, int atlassizezlimit, IntRef retCount)
    {
        BitmapData_ orig = BitmapData_.CreateFromBitmap(p, atlas2d_);

        int tilesize = orig.width / tiles;

        int atlasescount = MathCi.MaxInt(1, (tiles * tiles * tilesize) / atlassizezlimit);

        BitmapCi[] atlases      = new BitmapCi[128];
        int        atlasesCount = 0;

        BitmapData_ atlas1d = null;

        for (int i = 0; i < tiles * tiles; i++)
        {
            int x            = i % tiles;
            int y            = i / tiles;
            int tilesinatlas = (tiles * tiles / atlasescount);
            if (i % tilesinatlas == 0)
            {
                if (atlas1d != null)
                {
                    atlases[atlasesCount++] = atlas1d.ToBitmap(p);
                }
                atlas1d = BitmapData_.Create(tilesize, atlassizezlimit);
            }
            for (int xx = 0; xx < tilesize; xx++)
            {
                for (int yy = 0; yy < tilesize; yy++)
                {
                    int c = orig.GetPixel(x * tilesize + xx, y * tilesize + yy);
                    atlas1d.SetPixel(xx, (i % tilesinatlas) * tilesize + yy, c);
                }
            }
        }
        atlases[atlasesCount++] = atlas1d.ToBitmap(p);
        retCount.value          = atlasescount;
        return(atlases);
    }
示例#35
0
 public abstract string[] DirectoryGetFiles(string path, IntRef length);
示例#36
0
 public AnimatedModelRenderer()
 {
     tempframes      = new Keyframe[256];
     tempframesCount = new IntRef();
     tempVec3        = new float[3];
 }
示例#37
0
    public override void OnKeyDown(Game game_, KeyEventArgs args)
    {
        if (game.guistate != GuiState.Normal)
        {
            //Don't open chat when not in normal game
            return;
        }
        int eKey = args.GetKeyCode();
        if (eKey == game.GetKey(GlKeys.Number7) && game.IsShiftPressed && game.GuiTyping == TypingState.None) // don't need to hit enter for typing commands starting with slash
        {
            game.GuiTyping = TypingState.Typing;
            game.IsTyping = true;
            game.GuiTypingBuffer = "";
            game.IsTeamchat = false;
            args.SetHandled(true);
            return;
        }
        if (eKey == game.GetKey(GlKeys.PageUp) && game.GuiTyping == TypingState.Typing)
        {
            ChatPageScroll++;
            args.SetHandled(true);
        }
        if (eKey == game.GetKey(GlKeys.PageDown) && game.GuiTyping == TypingState.Typing)
        {
            ChatPageScroll--;
            args.SetHandled(true);
        }
        ChatPageScroll = MathCi.ClampInt(ChatPageScroll, 0, game.ChatLinesCount / ChatLinesMaxToDraw);
        if (eKey == game.GetKey(GlKeys.Enter) || eKey == game.GetKey(GlKeys.KeypadEnter))
        {
            if (game.GuiTyping == TypingState.Typing)
            {
                game.typinglog[game.typinglogCount++] = game.GuiTypingBuffer;
                game.typinglogpos = game.typinglogCount;
                game.ClientCommand(game.GuiTypingBuffer);

                game.GuiTypingBuffer = "";
                game.IsTyping = false;

                game.GuiTyping = TypingState.None;
                game.platform.ShowKeyboard(false);
            }
            else if (game.GuiTyping == TypingState.None)
            {
                game.StartTyping();
            }
            else if (game.GuiTyping == TypingState.Ready)
            {
                game.platform.ConsoleWriteLine("Keyboard_KeyDown ready");
            }
            args.SetHandled(true);
            return;
        }
        if (game.GuiTyping == TypingState.Typing)
        {
            int key = eKey;
            if (key == game.GetKey(GlKeys.BackSpace))
            {
                if (StringTools.StringLength(game.platform, game.GuiTypingBuffer) > 0)
                {
                    game.GuiTypingBuffer = StringTools.StringSubstring(game.platform, game.GuiTypingBuffer, 0, StringTools.StringLength(game.platform, game.GuiTypingBuffer) - 1);
                }
                args.SetHandled(true);
                return;
            }
            if (game.keyboardStateRaw[game.GetKey(GlKeys.ControlLeft)] || game.keyboardStateRaw[game.GetKey(GlKeys.ControlRight)])
            {
                if (key == game.GetKey(GlKeys.V))
                {
                    if (game.platform.ClipboardContainsText())
                    {
                        game.GuiTypingBuffer = StringTools.StringAppend(game.platform, game.GuiTypingBuffer, game.platform.ClipboardGetText());
                    }
                    args.SetHandled(true);
                    return;
                }
            }
            if (key == game.GetKey(GlKeys.Up))
            {
                game.typinglogpos--;
                if (game.typinglogpos < 0) { game.typinglogpos = 0; }
                if (game.typinglogpos >= 0 && game.typinglogpos < game.typinglogCount)
                {
                    game.GuiTypingBuffer = game.typinglog[game.typinglogpos];
                }
                args.SetHandled(true);
            }
            if (key == game.GetKey(GlKeys.Down))
            {
                game.typinglogpos++;
                if (game.typinglogpos > game.typinglogCount) { game.typinglogpos = game.typinglogCount; }
                if (game.typinglogpos >= 0 && game.typinglogpos < game.typinglogCount)
                {
                    game.GuiTypingBuffer = game.typinglog[game.typinglogpos];
                }
                if (game.typinglogpos == game.typinglogCount)
                {
                    game.GuiTypingBuffer = "";
                }
                args.SetHandled(true);
            }
            //Handles player name autocomplete in chat
            if (eKey == game.GetKey(GlKeys.Tab) && game.platform.StringTrim(game.GuiTypingBuffer) != "")
            {
                IntRef partsLength = new IntRef();
                string[] parts = game.platform.StringSplit(game.GuiTypingBuffer, " ", partsLength);
                string completed = DoAutocomplete(parts[partsLength.value - 1]);
                if (completed == "")
                {
                    //No completion available. Abort.
                    args.SetHandled(true);
                    return;
                }
                else if (partsLength.value == 1)
                {
                    //Part is first word. Format as "<name>: "
                    game.GuiTypingBuffer = StringTools.StringAppend(game.platform, completed, ": ");
                }
                else
                {
                    //Part is not first. Just complete "<name> "
                    parts[partsLength.value - 1] = completed;
                    game.GuiTypingBuffer = StringTools.StringAppend(game.platform, game.platform.StringJoin(parts, " "), " ");
                }
                args.SetHandled(true);
                return;
            }
            args.SetHandled(true);
            return;
        }
    }
示例#38
0
 public abstract DisplayResolutionCi[] GetDisplayResolutions(IntRef resolutionsCount);
示例#39
0
 public abstract string[] DirectoryGetFiles(string path, IntRef length);
示例#40
0
    internal void DrawAmmo(Game game)
    {
        Packet_Item item = game.d_Inventory.RightHand[game.ActiveMaterial];

        if (item != null && item.ItemClass == Packet_ItemClassEnum.Block)
        {
            if (game.blocktypes[item.BlockId].IsPistol)
            {
                int    loaded = game.LoadedAmmo[item.BlockId];
                int    total  = game.TotalAmmo[item.BlockId];
                string s      = game.platform.StringFormat2("{0}/{1}", game.platform.IntToString(loaded), game.platform.IntToString(total - loaded));
                FontCi font   = new FontCi();
                font.family = "Arial";
                font.size   = 18;
                game.Draw2dText(s, font, game.Width() - game.TextSizeWidth(s, 18) - 50,
                                game.Height() - game.TextSizeHeight(s, 18) - 50, loaded == 0 ? IntRef.Create(Game.ColorFromArgb(255, 255, 0, 0)) : IntRef.Create(Game.ColorFromArgb(255, 255, 255, 255)), false);
                if (loaded == 0)
                {
                    font.size = 14;
                    string pressR = "Press R to reload";
                    game.Draw2dText(pressR, font, game.Width() - game.TextSizeWidth(pressR, 14) - 50,
                                    game.Height() - game.TextSizeHeight(s, 14) - 80, IntRef.Create(Game.ColorFromArgb(255, 255, 0, 0)), false);
                }
            }
        }
    }
示例#41
0
 public abstract DisplayResolutionCi[] GetDisplayResolutions(IntRef resolutionsCount);
示例#42
0
    internal void NextBullet(Game game, int bulletsshot)
    {
        float one    = 1;
        bool  left   = game.mouseLeft;
        bool  middle = game.mouseMiddle;
        bool  right  = game.mouseRight;

        bool IsNextShot = bulletsshot != 0;

        if (!game.leftpressedpicking)
        {
            if (game.mouseleftclick)
            {
                game.leftpressedpicking = true;
            }
            else
            {
                left = false;
            }
        }
        else
        {
            if (game.mouseleftdeclick)
            {
                game.leftpressedpicking = false;
                left = false;
            }
        }
        if (!left)
        {
            game.currentAttackedBlock = null;
        }

        Packet_Item item          = game.d_Inventory.RightHand[game.ActiveMaterial];
        bool        ispistol      = (item != null && game.blocktypes[item.BlockId].IsPistol);
        bool        ispistolshoot = ispistol && left;
        bool        isgrenade     = ispistol && game.blocktypes[item.BlockId].PistolType == Packet_PistolTypeEnum.Grenade;

        if (ispistol && isgrenade)
        {
            ispistolshoot = game.mouseleftdeclick;
        }
        //grenade cooking
        if (game.mouseleftclick)
        {
            game.grenadecookingstartMilliseconds = game.platform.TimeMillisecondsFromStart();
            if (ispistol && isgrenade)
            {
                if (game.blocktypes[item.BlockId].Sounds.ShootCount > 0)
                {
                    game.AudioPlay(game.platform.StringFormat("{0}.ogg", game.blocktypes[item.BlockId].Sounds.Shoot[0]));
                }
            }
        }
        float wait = ((one * (game.platform.TimeMillisecondsFromStart() - game.grenadecookingstartMilliseconds)) / 1000);

        if (isgrenade && left)
        {
            if (wait >= game.grenadetime && isgrenade && game.grenadecookingstartMilliseconds != 0)
            {
                ispistolshoot         = true;
                game.mouseleftdeclick = true;
            }
            else
            {
                return;
            }
        }
        else
        {
            game.grenadecookingstartMilliseconds = 0;
        }

        if (ispistol && game.mouserightclick && (game.platform.TimeMillisecondsFromStart() - game.lastironsightschangeMilliseconds) >= 500)
        {
            game.IronSights = !game.IronSights;
            game.lastironsightschangeMilliseconds = game.platform.TimeMillisecondsFromStart();
        }

        IntRef pick2count = new IntRef();
        Line3D pick       = new Line3D();

        GetPickingLine(game, pick, ispistolshoot);
        BlockPosSide[] pick2 = game.Pick(game.s, pick, pick2count);

        if (left)
        {
            game.handSetAttackDestroy = true;
        }
        else if (right)
        {
            game.handSetAttackBuild = true;
        }

        if (game.overheadcamera && pick2count.value > 0 && left)
        {
            //if not picked any object, and mouse button is pressed, then walk to destination.
            if (game.Follow == null)
            {
                //Only walk to destination when not following someone
                game.playerdestination = Vector3Ref.Create(pick2[0].blockPos[0], pick2[0].blockPos[1] + 1, pick2[0].blockPos[2]);
            }
        }
        bool pickdistanceok = (pick2count.value > 0) && (!ispistol);

        if (pickdistanceok)
        {
            if (game.Dist(pick2[0].blockPos[0] + one / 2, pick2[0].blockPos[1] + one / 2, pick2[0].blockPos[2] + one / 2,
                          pick.Start[0], pick.Start[1], pick.Start[2]) > CurrentPickDistance(game))
            {
                pickdistanceok = false;
            }
        }
        bool playertileempty = game.IsTileEmptyForPhysics(
            game.platform.FloatToInt(game.player.position.x),
            game.platform.FloatToInt(game.player.position.z),
            game.platform.FloatToInt(game.player.position.y + (one / 2)));
        bool playertileemptyclose = game.IsTileEmptyForPhysicsClose(
            game.platform.FloatToInt(game.player.position.x),
            game.platform.FloatToInt(game.player.position.z),
            game.platform.FloatToInt(game.player.position.y + (one / 2)));
        BlockPosSide pick0 = new BlockPosSide();

        if (pick2count.value > 0 &&
            ((pickdistanceok && (playertileempty || (playertileemptyclose))) ||
             game.overheadcamera)
            )
        {
            game.SelectedBlockPositionX = game.platform.FloatToInt(pick2[0].Current()[0]);
            game.SelectedBlockPositionY = game.platform.FloatToInt(pick2[0].Current()[1]);
            game.SelectedBlockPositionZ = game.platform.FloatToInt(pick2[0].Current()[2]);
            pick0 = pick2[0];
        }
        else
        {
            game.SelectedBlockPositionX = -1;
            game.SelectedBlockPositionY = -1;
            game.SelectedBlockPositionZ = -1;
            pick0.blockPos    = new float[3];
            pick0.blockPos[0] = -1;
            pick0.blockPos[1] = -1;
            pick0.blockPos[2] = -1;
        }
        PickEntity(game, pick, pick2, pick2count);
        if (game.cameratype == CameraType.Fpp || game.cameratype == CameraType.Tpp)
        {
            int ntileX = game.platform.FloatToInt(pick0.Current()[0]);
            int ntileY = game.platform.FloatToInt(pick0.Current()[1]);
            int ntileZ = game.platform.FloatToInt(pick0.Current()[2]);
            if (game.IsUsableBlock(game.map.GetBlock(ntileX, ntileZ, ntileY)))
            {
                game.currentAttackedBlock = Vector3IntRef.Create(ntileX, ntileZ, ntileY);
            }
        }
        if (game.GetFreeMouse())
        {
            if (pick2count.value > 0)
            {
                OnPick_(pick0);
            }
            return;
        }

        if ((one * (game.platform.TimeMillisecondsFromStart() - lastbuildMilliseconds) / 1000) >= BuildDelay(game) ||
            IsNextShot)
        {
            if (left && game.d_Inventory.RightHand[game.ActiveMaterial] == null)
            {
                game.SendPacketClient(ClientPackets.MonsterHit(game.platform.FloatToInt(2 + game.rnd.NextFloat() * 4)));
            }
            if (left && !fastclicking)
            {
                //todo animation
                fastclicking = false;
            }
            if ((left || right || middle) && (!isgrenade))
            {
                lastbuildMilliseconds = game.platform.TimeMillisecondsFromStart();
            }
            if (isgrenade && game.mouseleftdeclick)
            {
                lastbuildMilliseconds = game.platform.TimeMillisecondsFromStart();
            }
            if (game.reloadstartMilliseconds != 0)
            {
                PickingEnd(left, right, middle, ispistol);
                return;
            }
            if (ispistolshoot)
            {
                if ((!(game.LoadedAmmo[item.BlockId] > 0)) ||
                    (!(game.TotalAmmo[item.BlockId] > 0)))
                {
                    game.AudioPlay("Dry Fire Gun-SoundBible.com-2053652037.ogg");
                    PickingEnd(left, right, middle, ispistol);
                    return;
                }
            }
            if (ispistolshoot)
            {
                float toX = pick.End[0];
                float toY = pick.End[1];
                float toZ = pick.End[2];
                if (pick2count.value > 0)
                {
                    toX = pick2[0].blockPos[0];
                    toY = pick2[0].blockPos[1];
                    toZ = pick2[0].blockPos[2];
                }

                Packet_ClientShot shot = new Packet_ClientShot();
                shot.FromX     = game.SerializeFloat(pick.Start[0]);
                shot.FromY     = game.SerializeFloat(pick.Start[1]);
                shot.FromZ     = game.SerializeFloat(pick.Start[2]);
                shot.ToX       = game.SerializeFloat(toX);
                shot.ToY       = game.SerializeFloat(toY);
                shot.ToZ       = game.SerializeFloat(toZ);
                shot.HitPlayer = -1;

                for (int i = 0; i < game.entitiesCount; i++)
                {
                    if (game.entities[i] == null)
                    {
                        continue;
                    }
                    if (game.entities[i].drawModel == null)
                    {
                        continue;
                    }
                    Entity p_ = game.entities[i];
                    if (p_.networkPosition == null)
                    {
                        continue;
                    }
                    if (!p_.networkPosition.PositionLoaded)
                    {
                        continue;
                    }
                    float feetposX = p_.position.x;
                    float feetposY = p_.position.y;
                    float feetposZ = p_.position.z;
                    //var p = PlayerPositionSpawn;
                    Box3D bodybox  = new Box3D();
                    float headsize = (p_.drawModel.ModelHeight - p_.drawModel.eyeHeight) * 2; //0.4f;
                    float h        = p_.drawModel.ModelHeight - headsize;
                    float r        = one * 35 / 100;

                    bodybox.AddPoint(feetposX - r, feetposY + 0, feetposZ - r);
                    bodybox.AddPoint(feetposX - r, feetposY + 0, feetposZ + r);
                    bodybox.AddPoint(feetposX + r, feetposY + 0, feetposZ - r);
                    bodybox.AddPoint(feetposX + r, feetposY + 0, feetposZ + r);

                    bodybox.AddPoint(feetposX - r, feetposY + h, feetposZ - r);
                    bodybox.AddPoint(feetposX - r, feetposY + h, feetposZ + r);
                    bodybox.AddPoint(feetposX + r, feetposY + h, feetposZ - r);
                    bodybox.AddPoint(feetposX + r, feetposY + h, feetposZ + r);

                    Box3D headbox = new Box3D();

                    headbox.AddPoint(feetposX - r, feetposY + h, feetposZ - r);
                    headbox.AddPoint(feetposX - r, feetposY + h, feetposZ + r);
                    headbox.AddPoint(feetposX + r, feetposY + h, feetposZ - r);
                    headbox.AddPoint(feetposX + r, feetposY + h, feetposZ + r);

                    headbox.AddPoint(feetposX - r, feetposY + h + headsize, feetposZ - r);
                    headbox.AddPoint(feetposX - r, feetposY + h + headsize, feetposZ + r);
                    headbox.AddPoint(feetposX + r, feetposY + h + headsize, feetposZ - r);
                    headbox.AddPoint(feetposX + r, feetposY + h + headsize, feetposZ + r);

                    float[] p;
                    float   localeyeposX = game.EyesPosX();
                    float   localeyeposY = game.EyesPosY();
                    float   localeyeposZ = game.EyesPosZ();
                    p = Intersection.CheckLineBoxExact(pick, headbox);
                    if (p != null)
                    {
                        //do not allow to shoot through terrain
                        if (pick2count.value == 0 || (game.Dist(pick2[0].blockPos[0], pick2[0].blockPos[1], pick2[0].blockPos[2], localeyeposX, localeyeposY, localeyeposZ)
                                                      > game.Dist(p[0], p[1], p[2], localeyeposX, localeyeposY, localeyeposZ)))
                        {
                            if (!isgrenade)
                            {
                                Entity entity = new Entity();
                                Sprite sprite = new Sprite();
                                sprite.positionX = p[0];
                                sprite.positionY = p[1];
                                sprite.positionZ = p[2];
                                sprite.image     = "blood.png";
                                entity.sprite    = sprite;
                                entity.expires   = Expires.Create(one * 2 / 10);
                                game.EntityAddLocal(entity);
                            }
                            shot.HitPlayer = i;
                            shot.IsHitHead = 1;
                        }
                    }
                    else
                    {
                        p = Intersection.CheckLineBoxExact(pick, bodybox);
                        if (p != null)
                        {
                            //do not allow to shoot through terrain
                            if (pick2count.value == 0 || (game.Dist(pick2[0].blockPos[0], pick2[0].blockPos[1], pick2[0].blockPos[2], localeyeposX, localeyeposY, localeyeposZ)
                                                          > game.Dist(p[0], p[1], p[2], localeyeposX, localeyeposY, localeyeposZ)))
                            {
                                if (!isgrenade)
                                {
                                    Entity entity = new Entity();
                                    Sprite sprite = new Sprite();
                                    sprite.positionX = p[0];
                                    sprite.positionY = p[1];
                                    sprite.positionZ = p[2];
                                    sprite.image     = "blood.png";
                                    entity.sprite    = sprite;
                                    entity.expires   = Expires.Create(one * 2 / 10);
                                    game.EntityAddLocal(entity);
                                }
                                shot.HitPlayer = i;
                                shot.IsHitHead = 0;
                            }
                        }
                    }
                }
                shot.WeaponBlock = item.BlockId;
                game.LoadedAmmo[item.BlockId] = game.LoadedAmmo[item.BlockId] - 1;
                game.TotalAmmo[item.BlockId]  = game.TotalAmmo[item.BlockId] - 1;
                float projectilespeed = game.DeserializeFloat(game.blocktypes[item.BlockId].ProjectileSpeedFloat);
                if (projectilespeed == 0)
                {
                    {
                        Entity entity = game.CreateBulletEntity(
                            pick.Start[0], pick.Start[1], pick.Start[2],
                            toX, toY, toZ, 150);
                        game.EntityAddLocal(entity);
                    }
                }
                else
                {
                    float vX      = toX - pick.Start[0];
                    float vY      = toY - pick.Start[1];
                    float vZ      = toZ - pick.Start[2];
                    float vLength = game.Length(vX, vY, vZ);
                    vX /= vLength;
                    vY /= vLength;
                    vZ /= vLength;
                    vX *= projectilespeed;
                    vY *= projectilespeed;
                    vZ *= projectilespeed;
                    shot.ExplodesAfter = game.SerializeFloat(game.grenadetime - wait);

                    {
                        Entity grenadeEntity = new Entity();

                        Sprite sprite = new Sprite();
                        sprite.image          = "ChemicalGreen.png";
                        sprite.size           = 14;
                        sprite.animationcount = 0;
                        sprite.positionX      = pick.Start[0];
                        sprite.positionY      = pick.Start[1];
                        sprite.positionZ      = pick.Start[2];
                        grenadeEntity.sprite  = sprite;

                        Grenade_ projectile = new Grenade_();
                        projectile.velocityX    = vX;
                        projectile.velocityY    = vY;
                        projectile.velocityZ    = vZ;
                        projectile.block        = item.BlockId;
                        projectile.sourcePlayer = game.LocalPlayerId;

                        grenadeEntity.expires = Expires.Create(game.grenadetime - wait);

                        grenadeEntity.grenade = projectile;
                        game.EntityAddLocal(grenadeEntity);
                    }
                }
                Packet_Client packet = new Packet_Client();
                packet.Id   = Packet_ClientIdEnum.Shot;
                packet.Shot = shot;
                game.SendPacketClient(packet);

                if (game.blocktypes[item.BlockId].Sounds.ShootEndCount > 0)
                {
                    game.pistolcycle = game.rnd.Next() % game.blocktypes[item.BlockId].Sounds.ShootEndCount;
                    game.AudioPlay(game.platform.StringFormat("{0}.ogg", game.blocktypes[item.BlockId].Sounds.ShootEnd[game.pistolcycle]));
                }

                bulletsshot++;
                if (bulletsshot < game.DeserializeFloat(game.blocktypes[item.BlockId].BulletsPerShotFloat))
                {
                    NextBullet(game, bulletsshot);
                }

                //recoil
                game.player.position.rotx -= game.rnd.NextFloat() * game.CurrentRecoil();
                game.player.position.roty += game.rnd.NextFloat() * game.CurrentRecoil() * 2 - game.CurrentRecoil();

                PickingEnd(left, right, middle, ispistol);
                return;
            }
            if (ispistol && right)
            {
                PickingEnd(left, right, middle, ispistol);
                return;
            }
            if (pick2count.value > 0)
            {
                if (middle)
                {
                    int newtileX = game.platform.FloatToInt(pick0.Current()[0]);
                    int newtileY = game.platform.FloatToInt(pick0.Current()[1]);
                    int newtileZ = game.platform.FloatToInt(pick0.Current()[2]);
                    if (game.map.IsValidPos(newtileX, newtileZ, newtileY))
                    {
                        int  clonesource  = game.map.GetBlock(newtileX, newtileZ, newtileY);
                        int  clonesource2 = game.d_Data.WhenPlayerPlacesGetsConvertedTo()[clonesource];
                        bool gotoDone     = false;
                        //find this block in another right hand.
                        for (int i = 0; i < 10; i++)
                        {
                            if (game.d_Inventory.RightHand[i] != null &&
                                game.d_Inventory.RightHand[i].ItemClass == Packet_ItemClassEnum.Block &&
                                game.d_Inventory.RightHand[i].BlockId == clonesource2)
                            {
                                game.ActiveMaterial = i;
                                gotoDone            = true;
                            }
                        }
                        if (!gotoDone)
                        {
                            IntRef freehand = game.d_InventoryUtil.FreeHand(game.ActiveMaterial);
                            //find this block in inventory.
                            for (int i = 0; i < game.d_Inventory.ItemsCount; i++)
                            {
                                Packet_PositionItem k = game.d_Inventory.Items[i];
                                if (k == null)
                                {
                                    continue;
                                }
                                if (k.Value_.ItemClass == Packet_ItemClassEnum.Block &&
                                    k.Value_.BlockId == clonesource2)
                                {
                                    //free hand
                                    if (freehand != null)
                                    {
                                        game.WearItem(
                                            game.InventoryPositionMainArea(k.X, k.Y),
                                            game.InventoryPositionMaterialSelector(freehand.value));
                                        break;
                                    }
                                    //try to replace current slot
                                    if (game.d_Inventory.RightHand[game.ActiveMaterial] != null &&
                                        game.d_Inventory.RightHand[game.ActiveMaterial].ItemClass == Packet_ItemClassEnum.Block)
                                    {
                                        game.MoveToInventory(
                                            game.InventoryPositionMaterialSelector(game.ActiveMaterial));
                                        game.WearItem(
                                            game.InventoryPositionMainArea(k.X, k.Y),
                                            game.InventoryPositionMaterialSelector(game.ActiveMaterial));
                                    }
                                }
                            }
                        }
                        string[] sound = game.d_Data.CloneSound()[clonesource];
                        if (sound != null)            // && sound.Length > 0)
                        {
                            game.AudioPlay(sound[0]); //todo sound cycle
                        }
                    }
                }
                if (left || right)
                {
                    BlockPosSide tile = pick0;
                    int          newtileX;
                    int          newtileY;
                    int          newtileZ;
                    if (right)
                    {
                        newtileX = game.platform.FloatToInt(tile.Translated()[0]);
                        newtileY = game.platform.FloatToInt(tile.Translated()[1]);
                        newtileZ = game.platform.FloatToInt(tile.Translated()[2]);
                    }
                    else
                    {
                        newtileX = game.platform.FloatToInt(tile.Current()[0]);
                        newtileY = game.platform.FloatToInt(tile.Current()[1]);
                        newtileZ = game.platform.FloatToInt(tile.Current()[2]);
                    }
                    if (game.map.IsValidPos(newtileX, newtileZ, newtileY))
                    {
                        //Console.WriteLine(". newtile:" + newtile + " type: " + d_Map.GetBlock(newtileX, newtileZ, newtileY));
                        if (!(pick0.blockPos[0] == -1 &&
                              pick0.blockPos[1] == -1 &&
                              pick0.blockPos[2] == -1))
                        {
                            int blocktype;
                            if (left)
                            {
                                blocktype = game.map.GetBlock(newtileX, newtileZ, newtileY);
                            }
                            else
                            {
                                blocktype = ((game.BlockInHand() == null) ? 1 : game.BlockInHand().value);
                            }
                            if (left && blocktype == game.d_Data.BlockIdAdminium())
                            {
                                PickingEnd(left, right, middle, ispistol);
                                return;
                            }
                            string[] sound = left ? game.d_Data.BreakSound()[blocktype] : game.d_Data.BuildSound()[blocktype];
                            if (sound != null)            // && sound.Length > 0)
                            {
                                game.AudioPlay(sound[0]); //todo sound cycle
                            }
                        }
                        //normal attack
                        if (!right)
                        {
                            //attack
                            int posx = newtileX;
                            int posy = newtileZ;
                            int posz = newtileY;
                            game.currentAttackedBlock = Vector3IntRef.Create(posx, posy, posz);
                            if (!game.blockHealth.ContainsKey(posx, posy, posz))
                            {
                                game.blockHealth.Set(posx, posy, posz, game.GetCurrentBlockHealth(posx, posy, posz));
                            }
                            game.blockHealth.Set(posx, posy, posz, game.blockHealth.Get(posx, posy, posz) - game.WeaponAttackStrength());
                            float health = game.GetCurrentBlockHealth(posx, posy, posz);
                            if (health <= 0)
                            {
                                if (game.currentAttackedBlock != null)
                                {
                                    game.blockHealth.Remove(posx, posy, posz);
                                }
                                game.currentAttackedBlock = null;
                                OnPick(game, game.platform.FloatToInt(newtileX), game.platform.FloatToInt(newtileZ), game.platform.FloatToInt(newtileY),
                                       game.platform.FloatToInt(tile.Current()[0]), game.platform.FloatToInt(tile.Current()[2]), game.platform.FloatToInt(tile.Current()[1]),
                                       tile.collisionPos,
                                       right);
                            }
                            PickingEnd(left, right, middle, ispistol);
                            return;
                        }
                        if (!right)
                        {
                            game.particleEffectBlockBreak.StartParticleEffect(newtileX, newtileY, newtileZ);//must be before deletion - gets ground type.
                        }
                        if (!game.map.IsValidPos(newtileX, newtileZ, newtileY))
                        {
                            game.platform.ThrowException("");
                        }
                        OnPick(game, game.platform.FloatToInt(newtileX), game.platform.FloatToInt(newtileZ), game.platform.FloatToInt(newtileY),
                               game.platform.FloatToInt(tile.Current()[0]), game.platform.FloatToInt(tile.Current()[2]), game.platform.FloatToInt(tile.Current()[1]),
                               tile.collisionPos,
                               right);
                        //network.SendSetBlock(new Vector3((int)newtile.X, (int)newtile.Z, (int)newtile.Y),
                        //    right ? BlockSetMode.Create : BlockSetMode.Destroy, (byte)MaterialSlots[activematerial]);
                    }
                }
            }
        }
        PickingEnd(left, right, middle, ispistol);
    }
示例#43
0
 public abstract string[] ReadAllLines(string p, IntRef retCount);
示例#44
0
    void PickEntity(Game game, Line3D pick, BlockPosSide[] pick2, IntRef pick2count)
    {
        game.SelectedEntityId        = -1;
        game.currentlyAttackedEntity = -1;
        float one = 1;

        for (int i = 0; i < game.entitiesCount; i++)
        {
            if (game.entities[i] == null)
            {
                continue;
            }
            if (i == game.LocalPlayerId)
            {
                continue;
            }
            if (game.entities[i].drawModel == null)
            {
                continue;
            }
            Entity p_ = game.entities[i];
            if (p_.networkPosition == null)
            {
                continue;
            }
            if (!p_.networkPosition.PositionLoaded)
            {
                continue;
            }
            if (!p_.usable)
            {
                continue;
            }
            float feetposX = p_.position.x;
            float feetposY = p_.position.y;
            float feetposZ = p_.position.z;

            float dist = game.Dist(feetposX, feetposY, feetposZ, game.player.position.x, game.player.position.y, game.player.position.z);
            if (dist > 5)
            {
                continue;
            }

            //var p = PlayerPositionSpawn;
            Box3D bodybox = new Box3D();
            float h       = p_.drawModel.ModelHeight;
            float r       = one * 35 / 100;

            bodybox.AddPoint(feetposX - r, feetposY + 0, feetposZ - r);
            bodybox.AddPoint(feetposX - r, feetposY + 0, feetposZ + r);
            bodybox.AddPoint(feetposX + r, feetposY + 0, feetposZ - r);
            bodybox.AddPoint(feetposX + r, feetposY + 0, feetposZ + r);

            bodybox.AddPoint(feetposX - r, feetposY + h, feetposZ - r);
            bodybox.AddPoint(feetposX - r, feetposY + h, feetposZ + r);
            bodybox.AddPoint(feetposX + r, feetposY + h, feetposZ - r);
            bodybox.AddPoint(feetposX + r, feetposY + h, feetposZ + r);

            float[] p;
            float   localeyeposX = game.EyesPosX();
            float   localeyeposY = game.EyesPosY();
            float   localeyeposZ = game.EyesPosZ();
            p = Intersection.CheckLineBoxExact(pick, bodybox);
            if (p != null)
            {
                //do not allow to shoot through terrain
                if (pick2count.value == 0 || (game.Dist(pick2[0].blockPos[0], pick2[0].blockPos[1], pick2[0].blockPos[2], localeyeposX, localeyeposY, localeyeposZ)
                                              > game.Dist(p[0], p[1], p[2], localeyeposX, localeyeposY, localeyeposZ)))
                {
                    game.SelectedEntityId = i;
                    if (game.cameratype == CameraType.Fpp || game.cameratype == CameraType.Tpp)
                    {
                        game.currentlyAttackedEntity = i;
                    }
                }
            }
        }
    }
示例#45
0
 public abstract int[] StringToCharArray(string s, IntRef length);
示例#46
0
 public abstract string[] ReadAllLines(string p, IntRef retCount);
示例#47
0
 public abstract void TextSize(string text, float fontSize, IntRef outWidth, IntRef outHeight);
示例#48
0
 internal string[] GetSavegames(IntRef length)
 {
     string[] files = p.DirectoryGetFiles(p.PathSavegames(), length);
     string[] savegames = new string[length.value];
     int count = 0;
     for (int i = 0; i < length.value; i++)
     {
         if(StringEndsWith(files[i], ".mddbs"))
         {
             savegames[count++] = files[i];
         }
     }
     length.value = count;
     return savegames;
 }
示例#49
0
 static bool IsVersionDate(GamePlatform platform, string version)
 {
     IntRef versionCharsCount = new IntRef();
     int[] versionChars = platform.StringToCharArray(version, versionCharsCount);
     if (versionCharsCount.value >= 10)
     {
         if (versionChars[4] == 45 && versionChars[7] == 45) // '-'
         {
             return true;
         }
     }
     return false;
 }
示例#50
0
 public abstract string[] FileReadAllLines(string path, IntRef length);
示例#51
0
 public static int StringLength(GamePlatform p, string a)
 {
     IntRef aLength = new IntRef();
     int[] aChars = p.StringToCharArray(a, aLength);
     return aLength.value;
 }
示例#52
0
 public abstract byte[] GzipCompress(byte[] data, int dataLength, IntRef retLength);
示例#53
0
    //tiles = 16 means 16 x 16 atlas
    public BitmapCi[] Atlas2dInto1d(GamePlatform p, BitmapCi atlas2d_, int tiles, int atlassizezlimit, IntRef retCount)
    {
        BitmapData_ orig = BitmapData_.CreateFromBitmap(p, atlas2d_);

        int tilesize = orig.width / tiles;

        int atlasescount = MathCi.MaxInt(1, (tiles * tiles * tilesize) / atlassizezlimit);
        BitmapCi[] atlases = new BitmapCi[128];
        int atlasesCount = 0;

        BitmapData_ atlas1d = null;

        for (int i = 0; i < tiles * tiles; i++)
        {
            int x = i % tiles;
            int y = i / tiles;
            int tilesinatlas = (tiles * tiles / atlasescount);
            if (i % tilesinatlas == 0)
            {
                if (atlas1d != null)
                {
                    atlases[atlasesCount++] = atlas1d.ToBitmap(p);
                }
                atlas1d = BitmapData_.Create(tilesize, atlassizezlimit);
            }
            for (int xx = 0; xx < tilesize; xx++)
            {
                for (int yy = 0; yy < tilesize; yy++)
                {
                    int c = orig.GetPixel(x * tilesize + xx, y * tilesize + yy);
                    atlas1d.SetPixel(xx, (i % tilesinatlas) * tilesize + yy, c);
                }
            }
        }
        atlases[atlasesCount++] = atlas1d.ToBitmap(p);
        retCount.value = atlasescount;
        return atlases;
    }
示例#54
0
 public abstract int[] StringToCharArray(string s, IntRef length);
示例#55
0
    public override void OnNewFrameDraw2d(Game game_, float deltaTime)
    {
        game = game_;
        if (dataItems == null)
        {
            dataItems = new GameDataItemsClient();
            dataItems.game = game_;
            controller = ClientInventoryController.Create(game_);
            inventoryUtil = game.d_InventoryUtil;
        }
        if (game.guistate == GuiState.MapLoading)
        {
            return;
        }
        DrawMaterialSelector();
        if (game.guistate != GuiState.Inventory)
        {
            return;
        }
        if (ScrollingUpTimeMilliseconds != 0 && (game.platform.TimeMillisecondsFromStart() - ScrollingUpTimeMilliseconds) > 250)
        {
            ScrollingUpTimeMilliseconds = game.platform.TimeMillisecondsFromStart();
            ScrollUp();
        }
        if (ScrollingDownTimeMilliseconds != 0 && (game.platform.TimeMillisecondsFromStart() - ScrollingDownTimeMilliseconds) > 250)
        {
            ScrollingDownTimeMilliseconds = game.platform.TimeMillisecondsFromStart();
            ScrollDown();
        }

        PointRef scaledMouse = PointRef.Create(game.mouseCurrentX, game.mouseCurrentY);

        game.Draw2dBitmapFile("inventory.png", InventoryStartX(), InventoryStartY(), 1024, 1024);

        //the3d.Draw2dTexture(terrain, 50, 50, 50, 50, 0);
        //the3d.Draw2dBitmapFile("inventory_weapon_shovel.png", 100, 100, 60 * 2, 60 * 4);
        //the3d.Draw2dBitmapFile("inventory_gauntlet_gloves.png", 200, 200, 60 * 2, 60 * 2);
        //main inventory
        for (int i = 0; i < game.d_Inventory.ItemsCount; i++)
        {
            Packet_PositionItem k = game.d_Inventory.Items[i];
            if (k == null)
            {
                continue;
            }
            int screeny = k.Y - ScrollLine;
            if (screeny >= 0 && screeny < CellCountInPageY)
            {
                DrawItem(CellsStartX() + k.X * CellDrawSize, CellsStartY() + screeny * CellDrawSize, k.Value_, 0, 0);
            }
        }

        //draw area selection
        if (game.d_Inventory.DragDropItem != null)
        {
            PointRef selectedInPage = SelectedCell(scaledMouse);
            if (selectedInPage != null)
            {
                int x = (selectedInPage.X) * CellDrawSize + CellsStartX();
                int y = (selectedInPage.Y) * CellDrawSize + CellsStartY();
                int sizex = dataItems.ItemSizeX(game.d_Inventory.DragDropItem);
                int sizey = dataItems.ItemSizeY(game.d_Inventory.DragDropItem);
                if (selectedInPage.X + sizex <= CellCountInPageX
                    && selectedInPage.Y + sizey <= CellCountInPageY)
                {
                    int c;
                    IntRef itemsAtAreaCount = new IntRef();
                    PointRef[] itemsAtArea = inventoryUtil.ItemsAtArea(selectedInPage.X, selectedInPage.Y + ScrollLine, sizex, sizey, itemsAtAreaCount);
                    if (itemsAtArea == null || itemsAtAreaCount.value > 1)
                    {
                        c = Game.ColorFromArgb(100, 255, 0, 0); // red
                    }
                    else //0 or 1
                    {
                        c = Game.ColorFromArgb(100, 0, 255, 0); // green
                    }
                    game.Draw2dTexture(game.WhiteTexture(), x, y,
                        CellDrawSize * sizex, CellDrawSize * sizey,
                        null, 0, c, false);
                }
            }
            IntRef selectedWear = SelectedWearPlace(scaledMouse);
            if (selectedWear != null)
            {
                PointRef p = PointRef.Create(wearPlaceStart[selectedWear.value].X + InventoryStartX(), wearPlaceStart[selectedWear.value].Y + InventoryStartY());
                PointRef size = wearPlaceCells[selectedWear.value];

                int c;
                Packet_Item itemsAtArea = inventoryUtil.ItemAtWearPlace(selectedWear.value, game.ActiveMaterial);
                if (!dataItems.CanWear(selectedWear.value, game.d_Inventory.DragDropItem))
                {
                    c = Game.ColorFromArgb(100, 255, 0, 0); // red
                }
                else //0 or 1
                {
                    c = Game.ColorFromArgb(100, 0, 255, 0); // green
                }
                game.Draw2dTexture(game.WhiteTexture(), p.X, p.Y,
                    CellDrawSize * size.X, CellDrawSize * size.Y,
                    null, 0, c, false);
            }
        }

        //material selector
        DrawMaterialSelector();

        //wear
        //DrawItem(Offset(wearPlaceStart[(int)WearPlace.LeftHand], InventoryStart), inventory.LeftHand[ActiveMaterial.ActiveMaterial], null);
        DrawItem(wearPlaceStart[WearPlace_.RightHand].X + InventoryStartX(), wearPlaceStart[WearPlace_.RightHand].Y + InventoryStartY(), game.d_Inventory.RightHand[game.ActiveMaterial], 0, 0);
        DrawItem(wearPlaceStart[WearPlace_.MainArmor].X + InventoryStartX(), wearPlaceStart[WearPlace_.MainArmor].Y + InventoryStartY(), game.d_Inventory.MainArmor, 0, 0);
        DrawItem(wearPlaceStart[WearPlace_.Boots].X + InventoryStartX(), wearPlaceStart[WearPlace_.Boots].Y + InventoryStartY(), game.d_Inventory.Boots, 0, 0);
        DrawItem(wearPlaceStart[WearPlace_.Helmet].X + InventoryStartX(), wearPlaceStart[WearPlace_.Helmet].Y + InventoryStartY(), game.d_Inventory.Helmet, 0, 0);
        DrawItem(wearPlaceStart[WearPlace_.Gauntlet].X + InventoryStartX(), wearPlaceStart[WearPlace_.Gauntlet].Y + InventoryStartY(), game.d_Inventory.Gauntlet, 0, 0);

        //info
        if (SelectedCell(scaledMouse) != null)
        {
            PointRef selected = SelectedCell(scaledMouse);
            selected.Y += ScrollLine;
            PointRef itemAtCell = inventoryUtil.ItemAtCell(selected);
            if (itemAtCell != null)
            {
                Packet_Item item = GetItem(game.d_Inventory, itemAtCell.X, itemAtCell.Y);
                if (item != null)
                {
                    int x = (selected.X) * CellDrawSize + CellsStartX();
                    int y = (selected.Y) * CellDrawSize + CellsStartY();
                    DrawItemInfo(scaledMouse.X, scaledMouse.Y, item);
                }
            }
        }
        if (SelectedWearPlace(scaledMouse) != null)
        {
            int selected = SelectedWearPlace(scaledMouse).value;
            Packet_Item itemAtWearPlace = inventoryUtil.ItemAtWearPlace(selected, game.ActiveMaterial);
            if (itemAtWearPlace != null)
            {
                DrawItemInfo(scaledMouse.X, scaledMouse.Y, itemAtWearPlace);
            }
        }
        if (SelectedMaterialSelectorSlot(scaledMouse) != null)
        {
            int selected = SelectedMaterialSelectorSlot(scaledMouse).value;
            Packet_Item item = game.d_Inventory.RightHand[selected];
            if (item != null)
            {
                DrawItemInfo(scaledMouse.X, scaledMouse.Y, item);
            }
        }

        if (game.d_Inventory.DragDropItem != null)
        {
            DrawItem(scaledMouse.X, scaledMouse.Y, game.d_Inventory.DragDropItem, 0, 0);
        }
    }
示例#56
0
 public TransitionInt(T owner, ref IntRef value1, int condition, eCompare compare = eCompare.EQUAL) : base(owner)
 {
     m_value     = value1;
     m_condition = condition;
     m_compare   = compare;
 }
示例#57
0
 public int StringLength(string a)
 {
     IntRef length = new IntRef();
     p.StringToCharArray(a, length);
     return length.value;
 }
示例#58
0
    public override void OnNewFrameDraw3d(Game game, float deltaTime)
    {
        for (int i = 0; i < game.entitiesCount; i++)
        {
            Entity e = game.entities[i];
            if (e == null)
            {
                continue;
            }
            if (e.drawName == null)
            {
                continue;
            }
            if (i == game.LocalPlayerId)
            {
                continue;
            }
            if (e.networkPosition != null && (!e.networkPosition.PositionLoaded))
            {
                continue;
            }
            int      kKey = i;
            DrawName p    = game.entities[i].drawName;
            if (p.OnlyWhenSelected)
            {
                continue;
            }
            float posX = p.TextX + e.position.x;
            float posY = p.TextY + e.position.y + e.drawModel.ModelHeight + game.one * 7 / 10;
            float posZ = p.TextZ + e.position.z;
            //todo if picking
            if ((game.Dist(game.player.position.x, game.player.position.y, game.player.position.z, posX, posY, posZ) < 20) ||
                game.keyboardState[Game.KeyAltLeft] || game.keyboardState[Game.KeyAltRight])
            {
                string name = p.Name;
                {
                    float shadow = (game.one * game.GetLight(game.platform.FloatToInt(posX), game.platform.FloatToInt(posZ), game.platform.FloatToInt(posY))) / Game.maxlight;
                    //do not interpolate player position if player is controlled by game world
                    //if (EnablePlayerUpdatePositionContainsKey(kKey) && !EnablePlayerUpdatePosition(kKey))
                    //{
                    //    posX = p.NetworkX;
                    //    posY = p.NetworkY;
                    //    posZ = p.NetworkZ;
                    //}
                    game.GLPushMatrix();
                    game.GLTranslate(posX, posY, posZ);
                    //if (p.Type == PlayerType.Monster)
                    //{
                    //    GLTranslate(0, 1, 0);
                    //}
                    ModDrawSprites.Billboard(game);
                    float scale = game.one * 2 / 100;
                    game.GLScale(scale, scale, scale);

                    //Color c = Color.FromArgb((int)(shadow * 255), (int)(shadow * 255), (int)(shadow * 255));
                    //Todo: Can't change text color because text has outline anyway.
                    if (p.DrawHealth)
                    {
                        game.Draw2dTexture(game.WhiteTexture(), -26, -11, 52, 12, null, 0, Game.ColorFromArgb(255, 0, 0, 0), false);
                        game.Draw2dTexture(game.WhiteTexture(), -25, -10, 50 * (game.one * p.Health), 10, null, 0, Game.ColorFromArgb(255, 255, 0, 0), false);
                    }
                    FontCi font = new FontCi();
                    font.family = "Arial";
                    font.size   = 14;
                    game.Draw2dText(name, font, -game.TextSizeWidth(name, 14) / 2, 0, IntRef.Create(Game.ColorFromArgb(255, 255, 255, 255)), true);
                    //                        GL.Translate(0, 1, 0);
                    game.GLPopMatrix();
                }
            }
        }
    }
示例#59
0
    TextTexture GetTextTexture(string text, float fontSize)
    {
        for (int i = 0; i < textTexturesCount; i++)
        {
            TextTexture t = textTextures[i];
            if (t == null)
            {
                continue;
            }
            if (t.text == text && t.size == fontSize)
            {
                return t;
            }
        }
        TextTexture textTexture = new TextTexture();

        Text_ text_ = new Text_();
        text_.text = text;
        text_.fontsize = fontSize;
        text_.fontfamily = "Arial";
        text_.color = Game.ColorFromArgb(255, 255, 255, 255);
        BitmapCi textBitmap = textColorRenderer.CreateTextTexture(text_);

        int texture = p.LoadTextureFromBitmap(textBitmap);

        IntRef textWidth = new IntRef();
        IntRef textHeight = new IntRef();
        p.TextSize(text, fontSize, textWidth, textHeight);

        textTexture.texture = texture;
        textTexture.texturewidth = p.FloatToInt(p.BitmapGetWidth(textBitmap));
        textTexture.textureheight = p.FloatToInt(p.BitmapGetHeight(textBitmap));
        textTexture.text = text;
        textTexture.size = fontSize;
        textTexture.textwidth = textWidth.value;
        textTexture.textheight = textHeight.value;

        p.BitmapDelete(textBitmap);

        textTextures[textTexturesCount++] = textTexture;
        return textTexture;
    }
示例#60
0
 bool IsEmptySpaceForPlayer(bool high, float x, float y, float z, IntRef blockingBlockType)
 {
     return(IsEmptyPoint(x, y, z, blockingBlockType) &&
            IsEmptyPoint(x, y + 1, z, blockingBlockType) &&
            (!high || IsEmptyPoint(x, y + 2, z, blockingBlockType)));
 }