Example #1
0
 public static void RefreshCache(string designName, ProtoBuf.AIDesign design)
 {
     if (designs.ContainsKey(designName))
     {
         designs[designName] = design;
     }
 }
Example #2
0
    private bool LoadAIDesign(ProtoBuf.AIDesign design, BasePlayer player)
    {
        if (design == null)
        {
            Debug.LogError(GetEntity().gameObject.name + " failed to load AI design!");
            return(false);
        }
        if (player != null)
        {
            AIDesignScope scope = (AIDesignScope)design.scope;
            if (scope == AIDesignScope.Default && !player.IsDeveloper)
            {
                return(false);
            }
            if (scope == AIDesignScope.EntityServerWide && !player.IsDeveloper && !player.IsAdmin)
            {
                return(false);
            }
        }
        if (AIDesign == null)
        {
            return(false);
        }
        AIDesign.Load(design, base.baseEntity);
        AIStateContainer defaultStateContainer = AIDesign.GetDefaultStateContainer();

        if (defaultStateContainer != null)
        {
            SwitchToState(defaultStateContainer.State, defaultStateContainer.ID);
        }
        return(true);
    }
Example #3
0
 public static ProtoBuf.AIDesign GetByNameOrInstance(string designName, ProtoBuf.AIDesign entityDesign)
 {
     if (entityDesign != null)
     {
         return(entityDesign);
     }
     ProtoBuf.AIDesign byName = GetByName(designName + "_custom");
     if (byName != null)
     {
         return(byName);
     }
     return(GetByName(designName));
 }
Example #4
0
    public void SaveDesign()
    {
        if (AIDesign == null)
        {
            return;
        }
        ProtoBuf.AIDesign aIDesign = AIDesign.ToProto(currentStateContainerID);
        string            text     = "cfg/ai/";
        string            filename = DefaultDesignSO.Filename;

        switch (AIDesign.Scope)
        {
        case AIDesignScope.Default:
            text += filename;
            try
            {
                using (FileStream stream2 = File.Create(text))
                {
                    ProtoBuf.AIDesign.Serialize(stream2, aIDesign);
                }
                AIDesigns.RefreshCache(filename, aIDesign);
            }
            catch (Exception)
            {
                Debug.LogWarning("Error trying to save default AI Design: " + text);
            }
            break;

        case AIDesignScope.EntityServerWide:
            filename += "_custom";
            text     += filename;
            try
            {
                using (FileStream stream = File.Create(text))
                {
                    ProtoBuf.AIDesign.Serialize(stream, aIDesign);
                }
                AIDesigns.RefreshCache(filename, aIDesign);
            }
            catch (Exception)
            {
                Debug.LogWarning("Error trying to save server-wide AI Design: " + text);
            }
            break;

        case AIDesignScope.EntityInstance:
            break;
        }
    }
Example #5
0
    private void SubmitAIDesign(BaseEntity.RPCMessage msg)
    {
        ProtoBuf.AIDesign aIDesign = ProtoBuf.AIDesign.Deserialize(msg.read);
        if (!LoadAIDesign(aIDesign, msg.player))
        {
            return;
        }
        SaveDesign();
        if (aIDesign.scope == 2)
        {
            return;
        }
        T entity = GetEntity();

        BaseEntity[] array = BaseEntity.Util.FindTargets(entity.ShortPrefabName, false);
        if (array == null || array.Length == 0)
        {
            return;
        }
        BaseEntity[] array2 = array;
        foreach (BaseEntity baseEntity in array2)
        {
            if (baseEntity == null || baseEntity == entity)
            {
                continue;
            }
            EntityComponentBase[] components = baseEntity.Components;
            if (components == null)
            {
                continue;
            }
            EntityComponentBase[] array3 = components;
            for (int j = 0; j < array3.Length; j++)
            {
                IAIDesign iAIDesign;
                if ((iAIDesign = array3[j] as IAIDesign) != null)
                {
                    iAIDesign.LoadAIDesign(aIDesign, null);
                    break;
                }
            }
        }
    }
Example #6
0
 void IAIDesign.LoadAIDesign(ProtoBuf.AIDesign design, BasePlayer player)
 {
     LoadAIDesign(design, player);
 }