MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | #pragma strong_types |
| 2 | #pragma save_types |
| 3 | #pragma range_check |
| 4 | #pragma no_clone |
| 5 | #pragma pedantic |
| 6 | |
| 7 | #include <wizlevels.h> |
| 8 | #include <reputation.h> |
| 9 | |
| 10 | private mapping reputations = ([ ]); |
| 11 | |
| 12 | /* |
| 13 | * Argumente: |
| 14 | * repid = Reputation-ID im Repmaster |
| 15 | * value = Wert um den die Reputation geaendert werden soll, |
| 16 | * positiv oder negativ |
| 17 | * silent = Keine Std-Meldung ausgeben |
| 18 | * |
| 19 | * Return: |
| 20 | * REP_RET_WRONGARGS = Falsche Argumente |
| 21 | * REP_RET_INACTIVE = Rep inaktiv (kann derzeit nicht geaendert werden) |
| 22 | * REP_RET_INVALIDUID = Unzulaessie UID |
| 23 | * REP_RET_ALREADYMAX = Rep bereits maximum / minimum |
| 24 | * REP_RET_INVALIDREP = Reputation nicht vorhanden |
| 25 | * |
| 26 | * REP_RET_SUCCESS = Reputation wurde veraendert |
| 27 | * REP_RET_SUCCESSCUT = Reputation wurde auf Min / Max veraendert |
| 28 | */ |
| 29 | public varargs int ChangeReputation(string repid, int value, |
| 30 | int silent) { |
| 31 | string uid, changemsg; int newval; mapping rep; |
| 32 | |
| 33 | if(!intp(value) || !value || !stringp(repid) || !sizeof(repid)) |
| 34 | return REP_RET_WRONGARGS; |
| 35 | if(!mappingp(rep = REPMASTER->GetReputationData(repid))) |
| 36 | return REP_RET_INVALIDREP; |
| 37 | if(!(rep["flags"] & REP_FLAG_ACTIVE)) |
| 38 | return REP_RET_INACTIVE; |
| 39 | if(REPMASTER->CheckValidUid(repid, previous_object()) < 1) |
| 40 | return REP_RET_INVALIDUID; |
| 41 | if(reputations[repid] >= REP_MAXIMUM || reputations[repid] <= REP_MINIMUM) |
| 42 | return REP_RET_ALREADYMAX; |
| 43 | |
| 44 | if(reputations[repid] + value > REP_MAXIMUM) |
| 45 | newval = reputations[repid] + value - REP_MAXIMUM; |
| 46 | else if(reputations[repid] - value < REP_MINIMUM) |
| 47 | newval = reputations[repid] + value + REP_MINIMUM; |
| 48 | |
| 49 | if(!silent && |
| 50 | stringp(changemsg = REPMASTER->GetDefaultChangeMsg(repid, |
| 51 | newval || value))) |
| 52 | tell_object(this_object(), changemsg); |
| 53 | |
| 54 | reputations[repid] += newval || value; |
| 55 | |
| 56 | return newval ? REP_RET_SUCCESSCUT : REP_RET_SUCCESS; |
| 57 | } |
| 58 | |
| 59 | /* |
| 60 | * Argumente: |
| 61 | * repid = Reputation-ID im Repmaster |
| 62 | * |
| 63 | * Return: |
| 64 | * 0 = Reputation noch nicht veraendert / enthalten |
| 65 | * !0 = Reputationswert |
| 66 | */ |
| 67 | public int GetReputation(string repid) { return reputations[repid]; } |
| 68 | |
| 69 | /* |
| 70 | * Return: |
| 71 | * Mappingkopie aller gespeicherten Reputationswert |
| 72 | */ |
| 73 | public mapping GetReputations() { return copy(reputations); } |