private static void WriteConditions(Utf8JsonWriter writer,
                                        obj_f namesField,
                                        obj_f argsField,
                                        Dictionary <obj_f, object> properties)
    {
        var modNames = (IReadOnlyList <int>)properties[namesField];
        var modData  = (IReadOnlyList <int>)properties.GetValueOrDefault(argsField, new int[0]);

        writer.WriteStartArray();

        var argIdx = 0;

        foreach (var modNameHash in modNames)
        {
            var condition = GameSystems.D20.Conditions.GetByHash(modNameHash);

            if (condition.numArgs == 0)
            {
                writer.WriteStringValue(condition.condName);
                continue;
            }

            writer.WriteStartArray();
            writer.WriteStringValue(condition.condName);
            for (var i = 0; i < condition.numArgs; i++)
            {
                writer.WriteNumberValue(modData[argIdx++]);
            }

            writer.WriteEndArray();
        }

        writer.WriteEndArray();
    }
Ejemplo n.º 2
0
    public static int getObjVar(GameObject obj, obj_f var, int idx, int mask, int bits)
    {
        var bitMask = mask << (idx * bits);
        var val     = obj.GetInt32(var) & bitMask;

        val = val >> (idx * bits);
        return(val & mask);
    }
Ejemplo n.º 3
0
    public static void setObjVar(GameObject obj, obj_f var, int idx, int val, int mask, int bits)
    {
        // print "obj=", object, " var=", var, " idx=", idx, " val=", val
        var bitMask = mask << (idx * bits);

        val = val << (idx * bits);
        var oldVal = obj.GetInt32(var) & ~bitMask;

        obj.SetInt32(var, oldVal | val);
    }
Ejemplo n.º 4
0
 public static void SetInt(this GameObject obj, obj_f field, int value)
 {
     if (field == obj_f.critter_subdual_damage)
     {
         GameSystems.MapObject.ChangeSubdualDamage(obj, value);
     }
     else
     {
         obj.SetInt32(field, value);
     }
 }
Ejemplo n.º 5
0
    public static void WriteField(this Utf8JsonWriter writer, obj_f field, object value)
    {
        // Drop broken-ass radius and render-height
        if (field == obj_f.radius && ((float)value <= 0 || (float)value > 9999))
        {
            Console.WriteLine($"Dropping invalid radius: {value}");
            return;
        }

        if (field == obj_f.render_height_3d && ((float)value <= 0 || (float)value > 9999))
        {
            Console.WriteLine($"Dropping invalid render-height: {value}");
            return;
        }

        ref readonly var fieldDef = ref ObjectFields.GetFieldDef(field);
Ejemplo n.º 6
0
 public static void setObjVarDWord(GameObject obj, obj_f var, int val)
 {
     obj.SetInt32(var, val);
 }
Ejemplo n.º 7
0
 public static void setObjVarNibble(GameObject obj, obj_f var, int idx, int val)
 {
     setObjVar(obj, var, idx, val, 15, 4);
 }
    private static void WriteField(Utf8JsonWriter writer, Dictionary <obj_f, object> properties, obj_f field)
    {
        // Special handling that spans different fields
        switch (field)
        {
        case obj_f.permanent_mods:
            writer.WritePropertyName("permanent_mod_args");
            WriteConditions(writer, obj_f.permanent_mods, obj_f.permanent_mod_data, properties);
            break;

        case obj_f.permanent_mod_data:
            // Handled by permanent_mods
            break;

        case obj_f.item_pad_wielder_condition_array:
            writer.WritePropertyName("item_wielder_conditions");
            WriteConditions(writer,
                            obj_f.item_pad_wielder_condition_array,
                            obj_f.item_pad_wielder_argument_array,
                            properties);
            break;

        case obj_f.item_pad_wielder_argument_array:
            // Handled by item_pad_wielder_condition_array
            break;

        case obj_f.npc_standpoints:
            WriteNpcStandpoints(writer, properties);
            break;

        case obj_f.armor_flags:
            WriteArmorFlags(writer, (ArmorFlag)(int)properties[field]);
            break;

        default:
            writer.WriteField(field, properties[field]);
            break;
        }
    }
Ejemplo n.º 9
0
 public static void setObjVarByte(GameObject obj, obj_f var, int idx, int val)
 {
     setObjVar(obj, var, idx, val, 255, 8);
 }
Ejemplo n.º 10
0
 public static int getObjVarNibble(GameObject obj, obj_f var, int idx)
 {
     return(getObjVar(obj, var, idx, 15, 4));
 }
Ejemplo n.º 11
0
 public static void setObjVarWord(GameObject obj, obj_f var, int idx, int val)
 {
     setObjVar(obj, var, idx, val, 65535, 16);
 }
Ejemplo n.º 12
0
 public static int getObjVarByte(GameObject obj, obj_f var, int idx)
 {
     return(getObjVar(obj, var, idx, 255, 8));
 }
Ejemplo n.º 13
0
 public static int getObjVarWord(GameObject obj, obj_f var, int idx)
 {
     return(getObjVar(obj, var, idx, 65535, 16));
 }
Ejemplo n.º 14
0
 public static int GetInt(this GameObject obj, obj_f field)
 {
     return(obj.GetInt32(field));
 }
Ejemplo n.º 15
0
    // Util functions for getting & setting words, bytes and nibbles in object integers.
    // object = reference to the object containing the integer variable.
    // var	 = the variable to be used. e.g. obj_f_weapon_pad_i_2
    // idx	 = the index of the word (0-1), byte (0-3) or nibble (0-7) to use.
    // val	 = the value to be set.

    public static int getObjVarDWord(GameObject obj, obj_f var)
    {
        return(obj.GetInt32(var));
    }
Ejemplo n.º 16
0
    public object?GetFieldValue(obj_f field)
    {
        switch (field)
        {
        case obj_f.render_color:
            return(renderColor);

        case obj_f.render_colors:
            return(renderColors);

        case obj_f.render_palette:
            return(renderPalette);

        case obj_f.render_scale:
            return(renderScale);

        case obj_f.render_alpha:
            return(renderAlpha);

        case obj_f.render_x:
            return(renderX);

        case obj_f.render_y:
            return(renderY);

        case obj_f.render_width:
            return(renderWidth);

        case obj_f.render_height:
            return(renderHeight);

        case obj_f.palette:
            return(palette);

        case obj_f.color:
            return(color);

        case obj_f.colors:
            return(colors);

        case obj_f.render_flags:
            return(renderFlags);

        case obj_f.temp_id:
            return(tempId);

        case obj_f.light_handle:
            return(lightHandle);

        case obj_f.overlay_light_handles:
            return(overlayLightHandles);

        case obj_f.find_node:
            return(findNode);

        case obj_f.animation_handle:
            return(animationHandle);

        case obj_f.grapple_state:
            return(grappleState);

        default:
            throw new ArgumentOutOfRangeException(nameof(field), field, null);
        }
    }
Ejemplo n.º 17
0
    public void SetFieldValue(obj_f field, object newValue)
    {
        switch (field)
        {
        case obj_f.render_color:
            renderColor = (int)newValue;
            break;

        case obj_f.render_colors:
            renderColors = (int)newValue;
            break;

        case obj_f.render_palette:
            renderPalette = (int)newValue;
            break;

        case obj_f.render_scale:
            renderScale = (int)newValue;
            break;

        case obj_f.render_alpha:
            if (!ReferenceEquals(renderAlpha, newValue))
            {
                renderAlpha?.Dispose();
            }

            renderAlpha = (SparseArray <int>)newValue;
            break;

        case obj_f.render_x:
            renderX = (int)newValue;
            break;

        case obj_f.render_y:
            renderY = (int)newValue;
            break;

        case obj_f.render_width:
            renderWidth = (int)newValue;
            break;

        case obj_f.render_height:
            renderHeight = (int)newValue;
            break;

        case obj_f.palette:
            palette = (int)newValue;
            break;

        case obj_f.color:
            color = (int)newValue;
            break;

        case obj_f.colors:
            colors = (int)newValue;
            break;

        case obj_f.render_flags:
            renderFlags = (int)newValue;
            break;

        case obj_f.temp_id:
            tempId = (int)newValue;
            break;

        case obj_f.light_handle:
            lightHandle = (int)newValue;
            break;

        case obj_f.overlay_light_handles:
            if (!ReferenceEquals(overlayLightHandles, newValue))
            {
                overlayLightHandles?.Dispose();
            }

            overlayLightHandles = (SparseArray <int>)newValue;
            break;

        case obj_f.find_node:
            findNode = (int)newValue;
            break;

        case obj_f.animation_handle:
            animationHandle = (int)newValue;
            break;

        case obj_f.grapple_state:
            grappleState = (int)newValue;
            break;

        default:
            throw new ArgumentOutOfRangeException(nameof(field), field, null);
        }
    }