-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathApi.cs
76 lines (66 loc) · 2.78 KB
/
Api.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using SpaceCore.Overrides;
using SpaceShared;
using StardewValley;
using StardewValley.TerrainFeatures;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace SpaceCore
{
public interface IApi
{
string[] GetCustomSkills();
int GetLevelForCustomSkill(Farmer farmer, string skill);
void AddExperienceForCustomSkill(Farmer farmer, string skill, int amt);
int GetProfessionId(string skill, string profession);
// Must take (Event, GameLocation, GameTime, string[])
void AddEventCommand( string command, MethodInfo info );
// Must have [XmlType("Mods_SOMETHINGHERE")] attribute (required to start with "Mods_")
void RegisterSerializerType( Type type );
}
public class Api : IApi
{
public string[] GetCustomSkills()
{
return Skills.GetSkillList();
}
public int GetLevelForCustomSkill(Farmer farmer, string skill)
{
return Skills.GetSkillLevel(farmer, skill);
}
public void AddExperienceForCustomSkill(Farmer farmer, string skill, int amt)
{
farmer.AddCustomSkillExperience(skill, amt);
}
public int GetProfessionId(string skill, string profession)
{
return Skills.GetSkill(skill).Professions.Single(p => p.Id == profession).GetVanillaId();
}
public void AddEventCommand( string command, MethodInfo info )
{
if ( info.GetParameters().Length != 4 )
throw new ArgumentException( "Custom event method must take Must take (Event, GameLocation, GameTime, string[])" );
if ( info.GetParameters()[ 0 ].ParameterType != typeof( Event ) ||
info.GetParameters()[ 1 ].ParameterType != typeof( GameLocation ) ||
info.GetParameters()[ 2 ].ParameterType != typeof( GameTime ) ||
info.GetParameters()[ 3 ].ParameterType != typeof( string[] ) )
throw new ArgumentException( "Custom event method must take Must take (Event, GameLocation, GameTime, string[])" );
Log.debug( "Adding event command: " + command + " = " + info );
EventTryCommandPatch.customCommands.Add( command, info );
}
public void RegisterSerializerType( Type type )
{
if ( !type.GetCustomAttribute< XmlTypeAttribute >().TypeName.StartsWith( "Mods_" ) )
{
throw new ArgumentException( "Custom types must have an [XmlType] attribute with the TypeName starting with \"Mods_\"" );
}
SpaceCore.modTypes.Add( type );
}
}
}