From 30b193b4634686bc0a752927e9d8c5cac55f2d32 Mon Sep 17 00:00:00 2001 From: gered Date: Wed, 6 Apr 2016 14:44:06 -0400 Subject: [PATCH] some protection against adding "nil" entities could occur in cases where a combat event has an optional source or target entity name and the handler code calls touch-entity for both (saves us from having to check for nil) --- .../src/vwowrla/core/encounters/analysis.clj | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/vwowrla.core/src/vwowrla/core/encounters/analysis.clj b/vwowrla.core/src/vwowrla/core/encounters/analysis.clj index 5cca80c..b2b9d89 100644 --- a/vwowrla.core/src/vwowrla/core/encounters/analysis.clj +++ b/vwowrla.core/src/vwowrla/core/encounters/analysis.clj @@ -2,6 +2,7 @@ (:import (java.util Date)) (:require + [clojure.string :as string] [clojure.tools.logging :refer [info warn error]] [schema.core :as s]) (:use @@ -19,24 +20,27 @@ provided, or adds a new entity under the given name to the active encounter if it does not already exist. returns encounter with the updated entity information." [encounter :- Encounter - entity-name :- s/Str + entity-name :- (s/maybe s/Str) timestamp :- Date] - (if-not (get-in encounter [:entities entity-name]) - (assoc-in encounter [:entities entity-name] - {:name entity-name - :added-at timestamp - :last-activity-at timestamp - :damage {:in {:total 0} - :out {:total 0}} - :healing {:in {:total 0} - :out {:total 0}} - :skill-uses {} - :alive-dps 0 - :encounter-dps 0 - :deaths [] - :resurrections [] - :alive-duration 0}) - (assoc-in encounter [:entities entity-name :last-activity-at] timestamp))) + (if-not (string/blank? entity-name) + (if-not (get-in encounter [:entities entity-name]) + (assoc-in encounter [:entities entity-name] + {:name entity-name + :added-at timestamp + :last-activity-at timestamp + :damage {:in {:total 0} + :out {:total 0}} + :healing {:in {:total 0} + :out {:total 0}} + :skill-uses {} + :alive-dps 0 + :encounter-dps 0 + :resources {} + :deaths [] + :resurrections [] + :alive-duration 0}) + (assoc-in encounter [:entities entity-name :last-activity-at] timestamp)) + entity-name)) (s/defn get-entity-last-activity :- (s/maybe Date) [entity-name :- s/Str